Advertisement
konalisp

table.copy

Apr 20th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.41 KB | None | 0 0
  1. function table.copy(orig)
  2.     local orig_type = type(orig)
  3.     local copy
  4.     if orig_type == 'table' then
  5.         copy = {}
  6.         for orig_key, orig_value in next, orig, nil do
  7.             copy[table.copy(orig_key)] = table.copy(orig_value)
  8.         end
  9.         setmetatable(copy, table.copy(getmetatable(orig)))
  10.     else -- number, string, boolean, etc
  11.         copy = orig
  12.     end
  13.     return copy
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement