From d2eed169aed84c8e3860912dfcd8da15db334c79 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 25 Nov 2011 21:52:09 +0200 Subject: Add builtin.lua --- data/builtin.lua | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 data/builtin.lua (limited to 'data') diff --git a/data/builtin.lua b/data/builtin.lua new file mode 100644 index 000000000..ead1ed3a6 --- /dev/null +++ b/data/builtin.lua @@ -0,0 +1,102 @@ +function basic_dump2(o) + if type(o) == "number" then + return tostring(o) + elseif type(o) == "string" then + return string.format("%q", o) + elseif type(o) == "boolean" then + return tostring(o) + elseif type(o) == "function" then + return "" + elseif type(o) == "userdata" then + return "" + 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 "" + 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 "" + elseif type(o) == "userdata" then + return "" + elseif type(o) == "nil" then + return "nil" + else + error("cannot dump a " .. type(o)) + return nil + end +end + +-- +-- Built-in node types. Also defined in C. +-- + +minetest.register_node("air", { + drawtype = "airlike", + paramtype = "light", + light_propagates = true, + sunlight_propagates = true, + walkable = false, + pointable = false, + diggable = false, + buildable_to = false, + air_equivalent = true, +}) + +minetest.register_node("ignore", { + drawtype = "airlike", + paramtype = "none", + light_propagates = false, + sunlight_propagates = false, + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, -- A way to remove accidentally placed ignores + air_equivalent = true, +}) + -- cgit v1.2.3