From e9f64c53e695af025d289d5260a15ee01b3d76de Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 22 Nov 2021 08:55:43 +1100 Subject: [PATCH] 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. --- imports/table/shared.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/imports/table/shared.lua b/imports/table/shared.lua index 24a0599..058988b 100644 --- a/imports/table/shared.lua +++ b/imports/table/shared.lua @@ -44,4 +44,15 @@ local function table_matches(t1, t2) end 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 \ No newline at end of file