I am porting some code from Flash and need to make a temporary duplicate of a multidimensional array and wondered if Lua has anything that can help?
In Flash, I would use
myArrayCopy = myArray.slice()
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
I am porting some code from Flash and need to make a temporary duplicate of a multidimensional array and wondered if Lua has anything that can help?
In Flash, I would use
myArrayCopy = myArray.slice()
May have found a solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function deepcopy(object) local lookup_table = {} local function _copy(object) if type(object) ~= "table" then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = {} lookup_table[object] = new_table for index, value in pairs(object) do new_table[_copy(index)] = _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end |