change DeepCopy(table) to DeepCopy(from,to)
This commit is contained in:
@@ -62,24 +62,36 @@ function Serialize(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Recursively deep-copy a table.
|
-- Recursively deep-copy a table.
|
||||||
function DeepCopy(t, already_copied)
|
function DeepCopy(From, To, already_copied)
|
||||||
|
if not To then To = {} end
|
||||||
|
|
||||||
already_copied = already_copied or { }
|
already_copied = already_copied or { }
|
||||||
|
already_copied[From] = To
|
||||||
|
|
||||||
if type(t) ~= "table" then
|
for a, b in pairs(From) do
|
||||||
return t
|
local aCopy, bCopy
|
||||||
|
if type(a) ~= "table" then
|
||||||
|
aCopy = a
|
||||||
|
elseif already_copied[a] then
|
||||||
|
aCopy = already_copied[a]
|
||||||
|
else
|
||||||
|
aCopy = {}
|
||||||
|
DeepCopy( a, aCopy, already_copied )
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(b) ~= "table" then
|
||||||
|
bCopy = b
|
||||||
|
elseif already_copied[b] then
|
||||||
|
bCopy = already_copied[b]
|
||||||
|
else
|
||||||
|
bCopy = {}
|
||||||
|
DeepCopy( b, bCopy, already_copied )
|
||||||
|
end
|
||||||
|
|
||||||
|
To[aCopy] = bCopy
|
||||||
end
|
end
|
||||||
|
|
||||||
if already_copied[t] then
|
return To
|
||||||
return already_copied[t]
|
|
||||||
end
|
|
||||||
already_copied[t] = { }
|
|
||||||
local ret = already_copied[t]
|
|
||||||
|
|
||||||
for a, b in pairs(t) do
|
|
||||||
ret[a] = DeepCopy( b, already_copied )
|
|
||||||
end
|
|
||||||
|
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- (c) 2005 Glenn Maynard
|
-- (c) 2005 Glenn Maynard
|
||||||
|
|||||||
Reference in New Issue
Block a user