-
-
Save ShadowNinja/6a6c0ac7141c0812c3b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- "copies" is an internal parameter | |
function table:deepcopy(copies) | |
if type(self) ~= "table" then | |
return self | |
end | |
local t = {} | |
copies = copies or {} | |
copies[self] = t | |
for k, v in pairs(self) do | |
t[copies[k] or table.deepcopy(k, copies)] = copies[v] or table.deepcopy(v, copies) | |
end | |
return t | |
end | |
function table:shallowcopy() | |
local t = {} | |
for k, v in pairs(self) do | |
t[k] = v | |
end | |
return t | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local k,o,d=next,type d=function(a,r,t)if o{}~=o(a)then return a end t={}r=r or{}r[a]=t for x,y in k,a do t[r[x]or d(x,r)]=r[y]or d(y,r)end return t end table.copy={shallow=function(a,b)b={}for x,y in k,a do b[x]=y end return b end,deep=d} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment