Skip to content

copy

copy(table) returns a shallow copy of a table. Only the first level of keys and values are copied. Nested tables are still shared by reference.

copy(table)
sync
Param Type Description
table table The table to copy
Value Type Description
shallow table A shallow copy (only first level is copied)
local original = { a = 1, b = { c = 2 } }
local shallow = copy(original)
shallow.a = 99 -- original.a is still 1
shallow.b.c = 99 -- original.b.c IS now 99