lua学习: lua的table类型
1、 table 是 lua 中最重要的数据类型。
2、 table 类似于 python 中的字典。
3、 table 只能通过构造式来创建
例1:
mytable = { 10, ddd = 30, 12, 13 }print(mytable[1])print(mytable[2])print(mytable[3])注释:
1)、 table 中可以出现没有 key 的项,这个时候,lua 会把这个 table 当做一个数组来看待,这个项的key就是它在数组中的下标(从1开始)
2)、 上例中, mytable[1] 是 10, mytable[2] 是 12, ddd = 30 这项会被跳过。mytable[3] 是 13
综上,可以发现, table 是一个数组和字典的混合体。