Table.clone: Difference between revisions

From GiderosMobile
m Text replacement - "<source" to "<syntaxhighlight"
No edit summary
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
Duplicates a table.
Duplicates a table.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table.clone(source,destination,deepclone)
(table) = table.clone(source)
</source>
</syntaxhighlight>
 
Returns a copy of the input table (''source'') that has the same metatable, same keys and values, and is not frozen even if source table was. The copy is shallow: implementing a deep recursive copy automatically is challenging, and often only certain keys need to be cloned recursively which can be done after the initial clone by modifying the resulting table.


=== Parameters ===
=== Parameters ===
'''source''': (table) the source table<br/>
'''source''': (table) the source table to clone<br/>
'''destination''': (table) a new table to clone to '''optional'''<br/>
 
'''deepclone''': (boolean) should the cloning be recursive '''optional, default = false'''<br/>
=== Return values ===
'''Returns''' (table) the new cloned table<br/>
 
=== Example ===
<syntaxhighlight lang="lua">
local table2 = table.clone(table1)
</syntaxhighlight>


{{Table}}
{{Table}}

Latest revision as of 02:19, 10 May 2026

Available since: Gideros 2022.3
Class: table

Description

Duplicates a table.

(table) = table.clone(source)

Returns a copy of the input table (source) that has the same metatable, same keys and values, and is not frozen even if source table was. The copy is shallow: implementing a deep recursive copy automatically is challenging, and often only certain keys need to be cloned recursively which can be done after the initial clone by modifying the resulting table.

Parameters

source: (table) the source table to clone

Return values

Returns (table) the new cloned table

Example

local table2 = table.clone(table1)