lua深拷贝

function CopyTable(tab)
    function _copy(obj)
        if type(obj) ~= "table" then
            return obj
        end
        local new_table = {}
        for k, v in pairs(obj) do
            new_table[_copy(k)] = _copy(v)
        end
        return setmetatable(new_table, getmetatable(obj))
    end
    return _copy(tab)
end

 

posted @ 2022-06-04 16:29  NAVYSUMMER  阅读(53)  评论(0)    收藏  举报
交流群 编程书籍