init.lua 1.9 KB

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