feat(table): add recursive clone function

table.clone creates a soft copy of an existing table (any tables inside the table will still be references).

This sets up a basic loop to clone any tables within a table and create deep copies.
This commit is contained in:
Linden
2021-11-22 08:55:43 +11:00
parent 90c0911c55
commit e9f64c53e6

View File

@@ -44,4 +44,15 @@ local function table_matches(t1, t2)
end end
table.matches = table_matches table.matches = table_matches
local function table_deepclone(tbl)
tbl = table.clone(tbl)
for k, v in pairs(tbl) do
if type(v) == 'table' then
tbl[k] = table_deepclone(v)
end
end
return tbl
end
table.deepclone = table_deepclone
return table return table