美文网首页
Lua中的table

Lua中的table

作者: Unity学习的路上 | 来源:发表于2017-03-31 21:07 被阅读0次

    表的相关函数

    concat 连接函数

    t1 = {"lucy"," and ","lily",1,2,["key"] = "value"}

    print(table.concat(t1)) --针对数组元素,无法连接字典元素

    insert 插入函数

    t1 = {"ello","world"}

    table.insert(t1,1,"h")

    print(t1[1]) --输出h,其他向后退

    sort 排序函数 默认升序

    针对number类型的排序

    t1 = {10,5,8,4,3,9}

    table.sort(t1)

    for i,v in ipairs(t1) do

    print(v)

    end

    还可以自定义一个排序方法

    function sortFunc(a,b)

    return a > b

    end

    table.sort(t1,sortFunc) --这样就实现了降序排序

    使用table可以模拟 面向对象的语言

    相关文章

      网友评论

          本文标题:Lua中的table

          本文链接:https://www.haomeiwen.com/subject/fxavottx.html