9951 explained code solutions for 126 technologies


luaHow to copy table


tbl_copy = {table.unpack(tbl)}ctrl + c
table.unpack

return list of table items instead of the table itself

tbl

table to copy

tbl_copy

variable with a new table copied from given


Usage example

tbl = {1, 2, 3}
tbl_copy = {table.unpack(tbl)}

table.insert(tbl_copy, 4);

print(table.concat(tbl, ','))
print(table.concat(tbl_copy, ','))
output
1,2,3
1,2,3,4