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