lua中的table
来源:互联网 发布:学画画软件 编辑:程序博客网 时间:2024/03/29 21:03
1、 table 是 lua 中最重要的数据类型。
2、 table 类似于 python 中的字典。
3、 table 只能通过构造式来创建
例1:
Lua代码
mytable = { a = 10, b = 11, c = 20, ddd = 30 }
print(mytable["a"])
注释:
1)、 table 中的每项要求是 key = value 的形式
2)、 key 只能是字符串, 这里的 a, b, c, ddd 都是字符串,但是不能加上引号
3)、 通过 key 来访问 table 的值,这时候, a 必须加上引号
例2:
Lua代码
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 是一个数组和字典的混合体。
2、 table 类似于 python 中的字典。
3、 table 只能通过构造式来创建
例1:
Lua代码
mytable = { a = 10, b = 11, c = 20, ddd = 30 }
print(mytable["a"])
注释:
1)、 table 中的每项要求是 key = value 的形式
2)、 key 只能是字符串, 这里的 a, b, c, ddd 都是字符串,但是不能加上引号
3)、 通过 key 来访问 table 的值,这时候, a 必须加上引号
例2:
Lua代码
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 是一个数组和字典的混合体。
- 【Lua】Lua中的Table操作
- 【lua】Lua中的table函数库
- LUA中的TABLE函数库
- LUA中的TABLE函数库
- Lua中的table函数库
- LUA中的TABLE函数库
- lua中的table
- Lua中的table函数库
- Lua语言中的table
- Lua中的table函数库
- Lua中的table函数库
- Lua中的table函数库
- Lua中的table函数库
- Lua中的table函数库
- Lua 中的table知识
- Lua中的table函数库
- Lua中的table函数库
- Lua中的table函数库
- plsql,sql,sql*plus之间的关系
- Android学习 - android编译系统makefile(Android.mk)写法
- 吴承恩竟在《西游记》中埋下这么一大伏笔!~
- 使用commons-fileupload解析文件,connection reset问题
- 你不知道的HTML5开发工具—GWT、VS2012和WebStorm
- lua中的table
- CIO关注:IT外包前的种种准备
- 合并两个排序链表
- 欢迎您在新浪博客安家
- 曲线图
- 我的ACM之路
- 冒泡排序
- qsort()排序函数
- HDU3177解题报告(qsort排序)