mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
fixup
This commit is contained in:
parent
e82440a096
commit
43ea6e34c1
1 changed files with 10 additions and 10 deletions
|
@ -25,16 +25,16 @@
|
||||||
-- @param obj table The table to clone.
|
-- @param obj table The table to clone.
|
||||||
-- @returns table A deep copy of the given table.
|
-- @returns table A deep copy of the given table.
|
||||||
local function deepcopy(obj, seen)
|
local function deepcopy(obj, seen)
|
||||||
-- Handle non-tables and previously-seen tables.
|
-- Handle non-tables and previously-seen tables.
|
||||||
if type(obj) ~= 'table' then return obj end
|
if type(obj) ~= 'table' then return obj end
|
||||||
if seen and seen[obj] then return seen[obj] end
|
if seen and seen[obj] then return seen[obj] end
|
||||||
|
|
||||||
-- New table; mark it as seen and copy recursively.
|
-- New table; mark it as seen and copy recursively.
|
||||||
local s = seen or {}
|
local s = seen or {}
|
||||||
local res = {}
|
local res = {}
|
||||||
s[obj] = res
|
s[obj] = res
|
||||||
for k, v in pairs(obj) do res[deepcopy(k, s)] = deepcopy(v, s) end
|
for k, v in pairs(obj) do res[deepcopy(k, s)] = deepcopy(v, s) end
|
||||||
return setmetatable(res, getmetatable(obj))
|
return setmetatable(res, getmetatable(obj))
|
||||||
end
|
end
|
||||||
|
|
||||||
return deepcopy
|
return deepcopy
|
||||||
|
|
Loading…
Reference in a new issue