File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -291,14 +291,19 @@ local clone = table.clone(original)
291291To copy a more complex table with nested tables inside it, you'll need to use a recursive function similar to the following:
292292
293293``` lua
294- local function deepCopy (original )
294+ -- The function used for deep copying a table
295+ local function deepCopy (original )
296+ -- Define the new table for the copy
295297 local copy = {}
296- for k , v in pairs (original ) do
297- if type (v ) == " table" then
298- v = deepCopy (v )
299- end
300- copy [k ] = v
298+
299+ -- Loop through the original table to clone
300+ for key , value in original do
301+ -- If the type of the value is a table, deep copy it to the key (index)
302+ -- Else (or) the type isn't a table, assign the default value to the index instead
303+ copy [key ] = type (value ) == " table" and deepCopy (value ) or value
301304 end
305+
306+ -- Return the finalized copy of the deep cloned table
302307 return copy
303308end
304309```
You can’t perform that action at this time.
0 commit comments