I have a table containing display objects. I need to copy this table to another table and then empty the original table. The problem seems to be that when I empty the original table, the values in the “new” table disappear as well. Here is the code:
local newTable = {}
function copyTable(oldTable)
newTable = {}
for i = 1, #oldTable do
if (oldTable[i].myType ~= nil) then
newTable[#newTable + 1] = oldTable[i]
end
end
for i = 1, #oldTable do
oldTable[i]:removeSelf()
oldTable[i] = nil
end
end
I have tried to “deep copy” the table (e.g. http://lua-users.org/wiki/CopyTable) but the values in the “new” table still disappear.
Any ideas?