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