lua table深度copy

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

你可能感兴趣的:(lua table深度copy)