1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add minetest.copy_table(table) To get rid off the "table references"

Signed-off-by: Craig Robbins <kde.psych@gmail.com>
This commit is contained in:
SmallJoker 2014-10-04 19:23:15 +02:00 committed by Craig Robbins
parent 77137a92cf
commit 6a43b3af09
2 changed files with 14 additions and 0 deletions

View file

@ -490,6 +490,18 @@ function core.pos_to_string(pos)
return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")"
end
--------------------------------------------------------------------------------
function table.copy(t, seen)
local n = {}
seen = seen or {}
seen[t] = n
for k, v in pairs(t) do
n[type(k) ~= "table" and k or seen[k] or table.copy(k, seen)] =
type(v) ~= "table" and v or seen[v] or table.copy(v, seen)
end
return n
end
--------------------------------------------------------------------------------
-- mainmenu only functions
--------------------------------------------------------------------------------