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