如何判断lua是不是一个纯数组类的table

来源:互联网 发布:企业建站cms无广告 编辑:程序博客网 时间:2024/05/16 13:49

这种方式只用遍历table一次,效果不错

function isArrayTable(t)    if type(t) ~= "table" then        return false    end    local n = #t    for i,v in pairs(t) do        if type(i) ~= "number" then            return false        end                if i > n then            return false        end     end    return true end


0 0
原创粉丝点击