Add builtin.lua
[oweals/minetest.git] / data / builtin.lua
1 function basic_dump2(o)
2         if type(o) == "number" then
3                 return tostring(o)
4         elseif type(o) == "string" then
5                 return string.format("%q", o)
6         elseif type(o) == "boolean" then
7                 return tostring(o)
8         elseif type(o) == "function" then
9                 return "<function>"
10         elseif type(o) == "userdata" then
11                 return "<userdata>"
12         elseif type(o) == "nil" then
13                 return "nil"
14         else
15                 error("cannot dump a " .. type(o))
16                 return nil
17         end
18 end
19
20 function dump2(o, name, dumped)
21         name = name or "_"
22         dumped = dumped or {}
23         io.write(name, " = ")
24         if type(o) == "number" or type(o) == "string" or type(o) == "boolean"
25                         or type(o) == "function" or type(o) == "nil"
26                         or type(o) == "userdata" then
27                 io.write(basic_dump2(o), "\n")
28         elseif type(o) == "table" then
29                 if dumped[o] then
30                         io.write(dumped[o], "\n")
31                 else
32                         dumped[o] = name
33                         io.write("{}\n") -- new table
34                         for k,v in pairs(o) do
35                                 local fieldname = string.format("%s[%s]", name, basic_dump2(k))
36                                 dump2(v, fieldname, dumped)
37                         end
38                 end
39         else
40                 error("cannot dump a " .. type(o))
41                 return nil
42         end
43 end
44
45 function dump(o, dumped)
46         dumped = dumped or {}
47         if type(o) == "number" then
48                 return tostring(o)
49         elseif type(o) == "string" then
50                 return string.format("%q", o)
51         elseif type(o) == "table" then
52                 if dumped[o] then
53                         return "<circular reference>"
54                 end
55                 dumped[o] = true
56                 local t = {}
57                 for k,v in pairs(o) do
58                         t[#t+1] = "" .. k .. " = " .. dump(v, dumped)
59                 end
60                 return "{" .. table.concat(t, ", ") .. "}"
61         elseif type(o) == "boolean" then
62                 return tostring(o)
63         elseif type(o) == "function" then
64                 return "<function>"
65         elseif type(o) == "userdata" then
66                 return "<userdata>"
67         elseif type(o) == "nil" then
68                 return "nil"
69         else
70                 error("cannot dump a " .. type(o))
71                 return nil
72         end
73 end
74
75 --
76 -- Built-in node types. Also defined in C.
77 --
78
79 minetest.register_node("air", {
80         drawtype = "airlike",
81         paramtype = "light",
82         light_propagates = true,
83         sunlight_propagates = true,
84         walkable = false,
85         pointable = false,
86         diggable = false,
87         buildable_to = false,
88         air_equivalent = true,
89 })
90
91 minetest.register_node("ignore", {
92         drawtype = "airlike",
93         paramtype = "none",
94         light_propagates = false,
95         sunlight_propagates = false,
96         walkable = false,
97         pointable = false,
98         diggable = false,
99         buildable_to = true, -- A way to remove accidentally placed ignores
100         air_equivalent = true,
101 })
102