diff --git a/env/functions.lua b/env/functions.lua index bd981474..68285529 100644 --- a/env/functions.lua +++ b/env/functions.lua @@ -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 \ No newline at end of file