init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --
  2. -- This file contains built-in stuff in Minetest implemented in Lua.
  3. --
  4. -- It is always loaded and executed after registration of the C API,
  5. -- before loading and running any mods.
  6. --
  7. -- Initialize some very basic things
  8. function core.error_handler(err, level)
  9. return debug.traceback(tostring(err), level)
  10. end
  11. do
  12. local function concat_args(...)
  13. local n, t = select("#", ...), {...}
  14. for i = 1, n do
  15. t[i] = tostring(t[i])
  16. end
  17. return table.concat(t, "\t")
  18. end
  19. function core.debug(...) core.log(concat_args(...)) end
  20. if core.print then
  21. local core_print = core.print
  22. -- Override native print and use
  23. -- terminal if that's turned on
  24. function print(...) core_print(concat_args(...)) end
  25. core.print = nil -- don't pollute our namespace
  26. end
  27. end
  28. math.randomseed(os.time())
  29. minetest = core
  30. -- Load other files
  31. local scriptdir = core.get_builtin_path()
  32. local commonpath = scriptdir .. "common" .. DIR_DELIM
  33. local asyncpath = scriptdir .. "async" .. DIR_DELIM
  34. dofile(commonpath .. "vector.lua")
  35. dofile(commonpath .. "strict.lua")
  36. dofile(commonpath .. "serialize.lua")
  37. dofile(commonpath .. "misc_helpers.lua")
  38. if INIT == "game" then
  39. dofile(scriptdir .. "game" .. DIR_DELIM .. "init.lua")
  40. assert(not core.get_http_api)
  41. elseif INIT == "mainmenu" then
  42. local mm_script = core.settings:get("main_menu_script")
  43. local custom_loaded = false
  44. if mm_script and mm_script ~= "" then
  45. local testfile = io.open(mm_script, "r")
  46. if testfile then
  47. testfile:close()
  48. dofile(mm_script)
  49. custom_loaded = true
  50. core.log("info", "Loaded custom main menu script: "..mm_script)
  51. else
  52. core.log("error", "Failed to load custom main menu script: "..mm_script)
  53. core.log("info", "Falling back to default main menu script")
  54. end
  55. end
  56. if not custom_loaded then
  57. dofile(core.get_mainmenu_path() .. DIR_DELIM .. "init.lua")
  58. end
  59. elseif INIT == "async" then
  60. dofile(asyncpath .. "mainmenu.lua")
  61. elseif INIT == "async_game" then
  62. dofile(commonpath .. "metatable.lua")
  63. dofile(asyncpath .. "game.lua")
  64. elseif INIT == "client" then
  65. dofile(scriptdir .. "client" .. DIR_DELIM .. "init.lua")
  66. elseif INIT == "emerge" then
  67. dofile(scriptdir .. "emerge" .. DIR_DELIM .. "init.lua")
  68. else
  69. error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
  70. end