mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 09:09:30 +00:00
util: clean table copy
This commit is contained in:
parent
6cf0fa4053
commit
d3f86d0275
1 changed files with 2 additions and 5 deletions
|
|
@ -189,14 +189,11 @@ util = {
|
||||||
-- @treturn table the copied table
|
-- @treturn table the copied table
|
||||||
copy = function(t, cache)
|
copy = function(t, cache)
|
||||||
if cache == nil then cache = {} end
|
if cache == nil then cache = {} end
|
||||||
|
if cache[t] then return cache[t] end
|
||||||
local r = {}
|
local r = {}
|
||||||
cache[t] = r
|
cache[t] = r
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if type(v) == "table" then
|
r[k] = type(v) == "table" and util.copy(v, cache) or v
|
||||||
r[k] = cache[v] or util.copy(v, cache)
|
|
||||||
else
|
|
||||||
r[k] = v
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return setmetatable(r, getmetatable(t))
|
return setmetatable(r, getmetatable(t))
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue