lua深拷贝
作者:
亮亮同学 | 来源:发表于
2019-02-24 21:08 被阅读1次local deepCopy = function(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
本文标题:lua深拷贝
本文链接:https://www.haomeiwen.com/subject/qtyrfqtx.html
网友评论