Advertisement
Guest User

deepcopy

a guest
Dec 14th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.33 KB | None | 0 0
  1. local function deepcopy(src, dest, cache, shallow)
  2.     cache = cache or {}
  3.     cache[src] = dest
  4.     for i, v in pairs(src) do
  5.         if type(v) == "table" and not shallow then
  6.             if not cache[v] then
  7.                 dest[i] = {}
  8.                 deepcopy(v,dest[i],cache)
  9.             else
  10.                 dest[i] = cache[v]
  11.             end
  12.         else
  13.             dest[i] = v
  14.         end
  15.     end
  16.     return dest
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement