table.deep_copy
Returns a deep copy of a table. Unlike table.copy, this function will create an independent copy of all tables nested within the original.
Usage
table.deep_copy(my_table)
Arguments
| Name | Type | Description |
|---|---|---|
my_table | table | Table to copy. |
Returns
| Name | Type | Description |
|---|---|---|
copied | table | Copy of the table. |
Examples
local party = { hero = { hp = 100, mp = 20 } };
local copy = table.deep_copy(party);
copy.hero.hp = 40;
print(copy.hero.hp); -- Prints "40"
print(party.hero.hp); -- Prints "100"