Skip to content

Instantly share code, notes, and snippets.

@dermotbalson
Created April 9, 2013 14:41
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 dermotbalson/5346219 to your computer and use it in GitHub Desktop.
Save dermotbalson/5346219 to your computer and use it in GitHub Desktop.
17.Copy
function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == '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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment