functions: add function to copy tables

This commit is contained in:
shagu
2016-12-23 19:35:27 +01:00
parent edd169eb78
commit 1e389f8097
+18
View File
@@ -35,3 +35,21 @@ function CreateGoldString(money)
return string
end
function CopyTable(src)
local lookup_table = {}
local function _copy(src)
if type(src) ~= "table" then
return src
elseif lookup_table[src] then
return lookup_table[src]
end
local new_table = {}
lookup_table[src] = new_table
for index, value in pairs(src) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(src))
end
return _copy(src)
end