Values & References7 / 10
Up next

Shallow copy

-- walk entries into a fresh table for a shallow copy
local function shallow_copy(t)
  local out = {}
  for k, v in pairs(t) do
    out[k] = v
  end
  return out
end
local a = {1, 2, 3}
local b = shallow_copy(a)
table.insert(b, 4)
print(#a, #b)
What you're solving

copy top-level entries into a new table