As aforementioned, foo variable is a reference to the table, it doesn't hold the actual table. It is possible, though, to do what you want by creating a copy of the original table, although you have to copy field by field and save metatables yourself (I suppose there are some implementions on the internet, perhaps search for table.deepcopy or deep_copy).
function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
setmetatable(copy, deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
TimeLoop wrote:Copying tables still doesn't work.
The values of the original table get modified anyway.
Any other solution?
What are you talking about? How do they get modified with a copy of the original table? Assigning a table variable to another variable doesn't copy it.
I used to be an adventurer like you, but then I took an arrow in the knee.