diff options
author | SmallJoker <mk939@ymail.com> | 2014-10-04 19:23:15 +0200 |
---|---|---|
committer | Craig Robbins <kde.psych@gmail.com> | 2014-11-27 18:19:01 +1000 |
commit | 6a43b3af09944f1d218b20be034ccb9e6ea073ff (patch) | |
tree | 5d5fba1e0d7b93b2ffb375ae5fbf4dd9329e7981 /builtin | |
parent | 77137a92cfc221b885b8eae68f13cede604fcac7 (diff) | |
download | minetest-6a43b3af09944f1d218b20be034ccb9e6ea073ff.tar.gz minetest-6a43b3af09944f1d218b20be034ccb9e6ea073ff.tar.bz2 minetest-6a43b3af09944f1d218b20be034ccb9e6ea073ff.zip |
Add minetest.copy_table(table) To get rid off the "table references"
Signed-off-by: Craig Robbins <kde.psych@gmail.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 12 |
1 files changed, 12 insertions, 0 deletions
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 @@ -491,6 +491,18 @@ function core.pos_to_string(pos) 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 -------------------------------------------------------------------------------- if INIT == "mainmenu" then |