Table.clone: Difference between revisions
From GiderosMobile
No edit summary |
No edit summary |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 5: | Line 5: | ||
=== Description === | === Description === | ||
Duplicates a table. | Duplicates a table. | ||
< | <syntaxhighlight lang="lua"> | ||
table.clone(source | (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/> | ||
''' | |||
=== 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)