Make a duplicate copy of a multidimensional array - similar to Flash slice()

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() [import]uid: 7863 topic_id: 8561 reply_id: 308561[/import]

May have found a solution:

[code]

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
[/code] [import]uid: 7863 topic_id: 8561 reply_id: 30724[/import]