]> git.lizzy.rs Git - xdecor.git/blob - handlers/helpers.lua
Global code style cleaning
[xdecor.git] / handlers / helpers.lua
1 -- Returns the greatest numeric key in a table.
2 function xdecor.maxn(T)
3         local n = 0
4         for k in pairs(T) do
5                 if k > n then
6                         n = k
7                 end
8         end
9
10         return n
11 end
12
13 -- Returns the length of an hash table.
14 function xdecor.tablelen(T)
15         local n = 0
16
17         for _ in pairs(T) do
18                 n = n + 1
19         end
20
21         return n
22 end
23
24 -- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
25 function xdecor.tablecopy(T)
26         if type(T) ~= "table" then
27                 return T -- No need to copy.
28         end
29
30         local new = {}
31
32         for k, v in pairs(T) do
33                 if type(v) == "table" then
34                         new[k] = xdecor.tablecopy(v)
35                 else
36                         new[k] = v
37                 end
38         end
39
40         return new
41 end
42
43 function xdecor.stairs_valid_def(def)
44         return (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
45                (def.groups.cracky or def.groups.choppy) and
46                 not def.on_construct and
47                 not def.after_place_node and
48                 not def.on_rightclick and
49                 not def.on_blast and
50                 not def.allow_metadata_inventory_take and
51                 not (def.groups.not_in_creative_inventory == 1) and
52                 not (def.groups.not_cuttable == 1) and
53                 not def.groups.wool and
54                 (def.tiles and type(def.tiles[1]) == "string" and not
55                 def.tiles[1]:find("default_mineral")) and
56                 not def.mesecons and
57                 def.description and
58                 def.description ~= "" and
59                 def.light_source == 0
60 end