2022-01-23 16:01:44 -07:00

35 lines
740 B
Lua

--- Miscellaneous functions
-- @module modpol.util.misc
modpol.util = {}
--- Returns a copy of the table inputted
-- @function modpol.util.copy_table
-- @param t table to copy
-- @return copy of table
function modpol.util.copy_table(t)
local t2 = {}
if pairs(t) then
for k,v in pairs(t) do
if type(v) == "table" then
t2[k] = modpol.util.copy_table(v)
else
t2[k] = v
end
end
end
return t2
end
--- Returns the number of elements in a pairs table
-- @function modpol.util.num_pairs
-- @param t pairs table
-- @return number of elements in pairs table
function modpol.util.num_pairs(t)
local i = 0
for k,v in pairs(t) do
i = i + 1
end
return i
end