Skip to content

Instantly share code, notes, and snippets.

@nefftd
Created April 28, 2014 20:18
Show Gist options
  • Save nefftd/11382847 to your computer and use it in GitHub Desktop.
Save nefftd/11382847 to your computer and use it in GitHub Desktop.
do
local function shallowcopy(tbl)
local new = {}
for k,v in next,tbl do
new[k] = v
end
return new
end
local function deepcopy(tbl)
local new = {}
for k,v in next,tbl do
if type(k) == 'table' then k = deepcopy(k) end
if type(v) == 'table' then v = deepcopy(v) end
new[k] = v
end
return new
end
function table.copy(tbl,deep)
argcheck(tbl,1,'table')
if deep then
return deepcopy(tbl)
else
return shallowcopy(tbl)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment