Created
April 28, 2014 20:18
-
-
Save nefftd/11382847 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
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