Created
September 17, 2014 16:27
-
-
Save anonymous/b66c3d75efb20cdc2e2f 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
local function copy(inp,copies) | |
local todo = {[inp] = {}} | |
copies = type(copies) == "table" and copies or {} | |
copies[inp] = todo[inp] | |
-- we can't use pairs or for here because we modify todo | |
while next(todo) do | |
local i,o = next(todo) | |
todo[i] = nil | |
for k,v in next,i do | |
if copies[k] ~= nil then | |
k = copies[k] | |
elseif type(k) == "table" then | |
local t = {} | |
todo[k] = t | |
copies[k] = t | |
k = t | |
end | |
if copies[v] ~= nil then | |
v = copies[v] | |
elseif type(v) == "table" then | |
local t = {} | |
todo[v] = t | |
copies[v] = t | |
v = t | |
end | |
rawset(o,k,v) | |
end | |
end | |
return copies[inp] -- heh :P | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment