copyTable = function (table)
local lookup_table={}
local function _copy(table)
if type(table) ~= "table" then
return table
elseif lookup_table[table] then
return lookup_table[table]
end
local new_table = {}
lookup_table[table] = new_table
for index, var in pairs(table) do
new_table[_copy(index)] = _copy(var)
end
return setmetatable(new_table,getmetatable(table))
end
return _copy(table)
end