Skip to content

Instantly share code, notes, and snippets.

-- "copies" is an internal parameter
function table:deepcopy(copies)
if type(self) ~= "table" then
return self
end
local t = {}
copies = copies or {}
copies[self] = t
for k, v in pairs(self) do
t[copies[k] or table.deepcopy(k, copies)] = copies[v] or table.deepcopy(v, copies)