File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -397,6 +397,31 @@ print(test[2]) --> 5
397397print(test[3]) --> 6
398398```
399399
400+ ---
401+ ### ` table.clone `
402+ Creates a copy of a table, optionally cloning nested tables up to a specified depth.
403+ #### Parameters
404+ 1 . The table to clone.
405+ 2 . The depth to clone to. Defaults to 100.
406+ #### Returns
407+ A new table containing the cloned values.
408+ ``` pluto
409+ local t = {
410+ a = {
411+ b = {
412+ c = {},
413+ },
414+ },
415+ }
416+
417+ local t1 = t:clone(1)
418+ assert(t1.a == t.a) -- depth 1 does not copy nested tables
419+
420+ local t2 = t:clone(2)
421+ assert(t2.a ~= t.a) -- 'a' is cloned
422+ assert(t2.a.b == t.a.b) -- but 'b' is shared
423+ ```
424+
400425---
401426### ` table.create `
402427Creates a new empty table, preallocating memory. Improves performance and memory usage when you know how many elements the table will have.
You can’t perform that action at this time.
0 commit comments