Skip to content

Instantly share code, notes, and snippets.

@ShadowNinja
Forked from SoniEx2/special.lua
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShadowNinja/6a6c0ac7141c0812c3b2 to your computer and use it in GitHub Desktop.
Save ShadowNinja/6a6c0ac7141c0812c3b2 to your computer and use it in GitHub Desktop.
-- "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
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