mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
22 lines
391 B
Lua
22 lines
391 B
Lua
local common
|
|
common = {
|
|
--- recursively copy a table, handle cyclic references, no metatable
|
|
copy = function(t, cache)
|
|
if type(t) == "table" then
|
|
cache = cache or {}
|
|
if cache[t] then
|
|
return cache[t]
|
|
else
|
|
local c = {}
|
|
cache[t] = c
|
|
for k, v in pairs(t) do
|
|
c[k] = common.copy(v, cache)
|
|
end
|
|
return c
|
|
end
|
|
else
|
|
return t
|
|
end
|
|
end
|
|
}
|
|
return common
|