mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02: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:
parent
77137a92cf
commit
6a43b3af09
@ -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
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -1310,6 +1310,8 @@ minetest.is_yes(arg)
|
||||
^ returns whether arg can be interpreted as yes
|
||||
minetest.get_us_time()
|
||||
^ returns time with microsecond precision
|
||||
table.copy(table) -> table
|
||||
^ returns a deep copy of a table
|
||||
|
||||
minetest namespace reference
|
||||
-----------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user