2,875
edits
No edit summary |
No edit summary |
||
Line 92: | Line 92: | ||
end | end | ||
end | end | ||
end | |||
-- Makes a deep copy of a table or otherwise object. | |||
-- Yoinked from http://lua-users.org/wiki/CopyTable | |||
function p.deepcopy(orig) | |||
local copy | |||
if type(orig) == 'table' then | |||
copy = {} | |||
for orig_key, orig_value in next, orig, nil do | |||
copy[deepcopy(orig_key)] = deepcopy(orig_value) | |||
end | |||
setmetatable(copy, deepcopy(getmetatable(orig))) | |||
else -- number, string, boolean, etc | |||
copy = orig | |||
end | |||
return copy | |||
end | end | ||
edits