init.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. do
  9. local function concat_args(...)
  10. local n, t = select("#", ...), {...}
  11. for i = 1, n do
  12. t[i] = tostring(t[i])
  13. end
  14. return table.concat(t, "\t")
  15. end
  16. function core.debug(...) core.log(concat_args(...)) end
  17. if core.print then
  18. local core_print = core.print
  19. -- Override native print and use
  20. -- terminal if that's turned on
  21. function print(...) core_print(concat_args(...)) end
  22. core.print = nil -- don't pollute our namespace
  23. end
  24. end
  25. math.randomseed(os.time())
  26. minetest = core
  27. -- Load other files
  28. local scriptdir = core.get_builtin_path()
  29. local gamepath = scriptdir .. "game" .. DIR_DELIM
  30. local clientpath = scriptdir .. "client" .. DIR_DELIM
  31. local commonpath = scriptdir .. "common" .. DIR_DELIM
  32. local asyncpath = scriptdir .. "async" .. DIR_DELIM
  33. dofile(commonpath .. "vector.lua")
  34. dofile(commonpath .. "strict.lua")
  35. dofile(commonpath .. "serialize.lua")
  36. dofile(commonpath .. "misc_helpers.lua")
  37. if INIT == "game" then
  38. dofile(gamepath .. "init.lua")
  39. assert(not core.get_http_api)
  40. elseif INIT == "mainmenu" then
  41. local mm_script = core.settings:get("main_menu_script")
  42. local custom_loaded = false
  43. if mm_script and mm_script ~= "" then
  44. local testfile = io.open(mm_script, "r")
  45. if testfile then
  46. testfile:close()
  47. dofile(mm_script)
  48. custom_loaded = true
  49. core.log("info", "Loaded custom main menu script: "..mm_script)
  50. else
  51. core.log("error", "Failed to load custom main menu script: "..mm_script)
  52. core.log("info", "Falling back to default main menu script")
  53. end
  54. end
  55. if not custom_loaded then
  56. dofile(core.get_mainmenu_path() .. DIR_DELIM .. "init.lua")
  57. end
  58. elseif INIT == "async" then
  59. dofile(asyncpath .. "mainmenu.lua")
  60. elseif INIT == "async_game" then
  61. dofile(asyncpath .. "game.lua")
  62. elseif INIT == "client" then
  63. dofile(clientpath .. "init.lua")
  64. else
  65. error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
  66. end