Skip to content

Commit

Permalink
Fix table deep clone
Browse files Browse the repository at this point in the history
  • Loading branch information
1Axen committed Mar 16, 2024
1 parent 45159fa commit 8e0caa0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Modules/Table.luau
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
return {
DeepClone = function(Table: {[any]: any}): {[any]: any}
local function Clone(Source: {[any]: any})
local Result = {}
for Index, Value in Source do
if type(Value) == "table" then
Result[Index] = Clone(Value)
local Clones = {}
local function Clone(Original)
local Result = Original
if type(Original) == "table" then
if Clones[Original] then
Result = Clones[Original]
else
Result[Index] = Value
Result = {}
Clones[Original] = Result
for Key, Value in Original do
Result[Clone(Key)] = Clone(Value)
end
end
end

Expand Down

0 comments on commit 8e0caa0

Please sign in to comment.