init.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. os.setlocale("C", "numeric")
  24. minetest = core
  25. -- Load other files
  26. local scriptdir = core.get_builtin_path()..DIR_DELIM
  27. local gamepath = scriptdir.."game"..DIR_DELIM
  28. local commonpath = scriptdir.."common"..DIR_DELIM
  29. local asyncpath = scriptdir.."async"..DIR_DELIM
  30. dofile(commonpath.."strict.lua")
  31. dofile(commonpath.."serialize.lua")
  32. dofile(commonpath.."misc_helpers.lua")
  33. if INIT == "game" then
  34. dofile(gamepath.."init.lua")
  35. elseif INIT == "mainmenu" then
  36. local mainmenuscript = core.setting_get("main_menu_script")
  37. if mainmenuscript ~= nil and mainmenuscript ~= "" then
  38. dofile(mainmenuscript)
  39. else
  40. dofile(core.get_mainmenu_path()..DIR_DELIM.."init.lua")
  41. end
  42. elseif INIT == "async" then
  43. dofile(asyncpath.."init.lua")
  44. else
  45. error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
  46. end