unity3D技术分享

lua table深度copy

2021-05-15  本文已影响0人  好怕怕
function table.DeepCopy(tab)
    if tab== nil then
        return nil
    end
    local copy = {}
    for k, v in pairs(tab) do
        if type(v) == 'table' then
            copy[k] = table.deepCopy(v)
        else
            copy[k] = v
        end
    end
    setmetatable(copy, table.deepCopy(getmetatable(tab)))
    return copy
end

上一篇 下一篇

猜你喜欢

热点阅读