当前位置: 首页 > 工具软件 > Table Library > 使用案例 >

table用法

艾照
2023-12-01
--getn获取元素的个数
    player ={
       {name = "yangchun",id = "100000001"},
       {name = "dlnuchunge",id = "100000002"},
       {name = "nate",id = "100000003"},
    }
    player[6] = {name = "666",id = "100000006"}
    print(table.getn(player))--3

    --sort
    function output(p)
        for k,v in pairs(p) do
           print(k,v.name)
        end
    end
    output(player)
    table.sort(player,function(a,b) return(a.name < b.name) end)
    output(player)
    
    --insert
    table.insert(player,3,{name = "333",id = "100000003"})
    output(player)

    --remove
    table.remove(player,3)
    output(player)

    --引用
    player.uuid = "1001"
    print(player.uuid)

    --多维table
    player.childArray = {1,2,3,4,5}
    for k,v in pairs(player.childArray) do
           print(k,v)
    end

 类似资料: