File: helpers.lua

package info (click to toggle)
minetest-mod-xdecor 1.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,048 kB
  • sloc: makefile: 4
file content (31 lines) | stat: -rw-r--r-- 629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- Returns the greatest numeric key in a table.
function xdecor.maxn(T)
	local n = 0
	for k in pairs(T) do
		if k > n then n = k end
	end
	return n
end

-- Returns the length of an hash table.
function xdecor.tablelen(T)
	local n = 0
	for _ in pairs(T) do n = n + 1 end
	return n
end

-- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
function xdecor.tablecopy(T)
	if type(T) ~= "table" then return T end -- No need to copy.
	local new = {}

	for k, v in pairs(T) do
		if type(v) == "table" then
			new[k] = xdecor.tablecopy(v)
		else
			new[k] = v
		end
	end
	return new
end