1
0
Fork 0
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:
Étienne Fildadut 2025-07-11 15:11:55 +02:00
parent 6cf0fa4053
commit d3f86d0275

View file

@ -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,