mirror of
https://github.com/minetest/minetest.git
synced 2024-11-24 00:23:46 +01:00
builtin.lua
This commit is contained in:
parent
9e7ad1e2aa
commit
61ffe1eac4
@ -1,77 +1,7 @@
|
|||||||
function basic_dump2(o)
|
-- Helper functions defined by builtin.lua:
|
||||||
if type(o) == "number" then
|
-- dump2(obj, name="_", dumped={})
|
||||||
return tostring(o)
|
-- dump(obj, dumped={})
|
||||||
elseif type(o) == "string" then
|
--
|
||||||
return string.format("%q", o)
|
|
||||||
elseif type(o) == "boolean" then
|
|
||||||
return tostring(o)
|
|
||||||
elseif type(o) == "function" then
|
|
||||||
return "<function>"
|
|
||||||
elseif type(o) == "userdata" then
|
|
||||||
return "<userdata>"
|
|
||||||
elseif type(o) == "nil" then
|
|
||||||
return "nil"
|
|
||||||
else
|
|
||||||
error("cannot dump a " .. type(o))
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function dump2(o, name, dumped)
|
|
||||||
name = name or "_"
|
|
||||||
dumped = dumped or {}
|
|
||||||
io.write(name, " = ")
|
|
||||||
if type(o) == "number" or type(o) == "string" or type(o) == "boolean"
|
|
||||||
or type(o) == "function" or type(o) == "nil"
|
|
||||||
or type(o) == "userdata" then
|
|
||||||
io.write(basic_dump2(o), "\n")
|
|
||||||
elseif type(o) == "table" then
|
|
||||||
if dumped[o] then
|
|
||||||
io.write(dumped[o], "\n")
|
|
||||||
else
|
|
||||||
dumped[o] = name
|
|
||||||
io.write("{}\n") -- new table
|
|
||||||
for k,v in pairs(o) do
|
|
||||||
local fieldname = string.format("%s[%s]", name, basic_dump2(k))
|
|
||||||
dump2(v, fieldname, dumped)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
error("cannot dump a " .. type(o))
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function dump(o, dumped)
|
|
||||||
dumped = dumped or {}
|
|
||||||
if type(o) == "number" then
|
|
||||||
return tostring(o)
|
|
||||||
elseif type(o) == "string" then
|
|
||||||
return string.format("%q", o)
|
|
||||||
elseif type(o) == "table" then
|
|
||||||
if dumped[o] then
|
|
||||||
return "<circular reference>"
|
|
||||||
end
|
|
||||||
dumped[o] = true
|
|
||||||
local t = {}
|
|
||||||
for k,v in pairs(o) do
|
|
||||||
t[#t+1] = "" .. k .. " = " .. dump(v, dumped)
|
|
||||||
end
|
|
||||||
return "{" .. table.concat(t, ", ") .. "}"
|
|
||||||
elseif type(o) == "boolean" then
|
|
||||||
return tostring(o)
|
|
||||||
elseif type(o) == "function" then
|
|
||||||
return "<function>"
|
|
||||||
elseif type(o) == "userdata" then
|
|
||||||
return "<userdata>"
|
|
||||||
elseif type(o) == "nil" then
|
|
||||||
return "nil"
|
|
||||||
else
|
|
||||||
error("cannot dump a " .. type(o))
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Textures:
|
-- Textures:
|
||||||
-- Mods should prefix their textures with modname_, eg. given the mod
|
-- Mods should prefix their textures with modname_, eg. given the mod
|
||||||
-- name "foomod", a texture could be called "foomod_superfurnace.png"
|
-- name "foomod", a texture could be called "foomod_superfurnace.png"
|
||||||
|
@ -1024,6 +1024,8 @@ Server::Server(
|
|||||||
// Initialize default node definitions
|
// Initialize default node definitions
|
||||||
content_mapnode_init(m_nodedef);
|
content_mapnode_init(m_nodedef);
|
||||||
|
|
||||||
|
// Path to builtin.lua
|
||||||
|
std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua";
|
||||||
// Add default global mod path
|
// Add default global mod path
|
||||||
m_modspaths.push_back(porting::path_data + DIR_DELIM + "mods");
|
m_modspaths.push_back(porting::path_data + DIR_DELIM + "mods");
|
||||||
|
|
||||||
@ -1034,7 +1036,16 @@ Server::Server(
|
|||||||
assert(m_lua);
|
assert(m_lua);
|
||||||
// Export API
|
// Export API
|
||||||
scriptapi_export(m_lua, this);
|
scriptapi_export(m_lua, this);
|
||||||
// Load and run scripts
|
// Load and run builtin.lua
|
||||||
|
infostream<<"Server: Loading builtin Lua stuff from \""<<builtinpath
|
||||||
|
<<"\""<<std::endl;
|
||||||
|
bool success = script_load(m_lua, builtinpath.c_str());
|
||||||
|
if(!success){
|
||||||
|
errorstream<<"Server: Failed to load and run "
|
||||||
|
<<builtinpath<<std::endl;
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
// Load and run "mod" scripts
|
||||||
core::list<ModSpec> mods = getMods(m_modspaths);
|
core::list<ModSpec> mods = getMods(m_modspaths);
|
||||||
for(core::list<ModSpec>::Iterator i = mods.begin();
|
for(core::list<ModSpec>::Iterator i = mods.begin();
|
||||||
i != mods.end(); i++){
|
i != mods.end(); i++){
|
||||||
|
Loading…
Reference in New Issue
Block a user