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