the function table.deepcopy defined in data/core/lualib/util.lua that allow to recursively copy a table does not work in the really particular case where the table is a metatable that modifies either the __index or the __pairs metamethods. In my case, I have a table with which I need to do particular things when an index is modified (like some sort of hook). To do it I use the __newindex metamethod to trigger the hook and I store the value in another hidden table (like in this). To make the table look like a normal table, I also modified the __index and __pairs metamethods to point to the hidden table. This makes the deepcopy function copy the hidden table and not the actual table.
I solved this problem in my mod by overriding the function and modifying the loop by this to ignore the metamethods:
Code: Select all
for index, value in next, object, nil do
rawset(new_table, _copy(index), _copy(value))
end