From 6a43b3af09944f1d218b20be034ccb9e6ea073ff Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 4 Oct 2014 19:23:15 +0200 Subject: Add minetest.copy_table(table) To get rid off the "table references" Signed-off-by: Craig Robbins --- builtin/common/misc_helpers.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'builtin') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 48488ab62..0b608126e 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -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 -------------------------------------------------------------------------------- -- cgit v1.2.3