mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
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:
@@ -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
|
||||||
Reference in New Issue
Block a user