Lua 之table的测试
来源:互联网 发布:淘宝10元包邮在哪 编辑:程序博客网 时间:2024/06/05 17:34
一.lua 的 table构造
1.字符串作为table索引
法1.
MyTable = {x = "xixi"}
法2.
MyTable = {["x"] = "xixi"}
法3.
MyTable = {}
MyTable.x = "xixi"
法4.
MyTable = {}
MyTable["x"] = "xixi"
注:
当使用数字字符串作为索引的时候(如:“10”):
法1(错误):MyTable = {10 = "xixi"}
法2:MyTable = {["10"] = "xixi"]}
法3(错误):MyTable = {} MyTable.10 = "xixi"
法4:MyTable = {} MyTable["10"] = "xixi"
2.数字作为table索引
法1.
MyTable = {[2] = "xixi"}
法2.
MyTable = {}
MyTable[2] = "xixi"
法3.
MyTable = {"x","y","z"}
这时候默认起始坐标为1,所以值为"y"对应的是MyTable[2]
3.字符串作为table索引,值为函数
法1.
x = {func =
function ()
print("x func call")
end
}
法2.
y = {["func"] =
function ()
print("y func call")
end
}
法3.
z = {}
z.func =
function ()
print("z func call")
end
法4.
w = {}
w["func"] =
function ()
print("w func call")
end
法5.(新增定义方法)
m = {}
function m.func()
print("m func call")
end
二.访问table的方法
法1.
MyTable[index]
法2.
MyTable.index
三.混合记录和列表风格的table构造式
polyline = {color = "blue",thickness = 2, "test",
{x=0,y=0},
{x=-10,y=10}
}
print(polyline.color) --blue
print(polyline[1]) --test
print(polyline[2].x) --0
- Lua 之table的测试
- lua学习笔记之table的遍历
- Cocos2d-Lua之table的遍历
- Cocos2d-Lua之table的排序
- lua数据结构之table的内部实现
- lua之table学习
- Lua银弹之table
- lua之table
- Cocos2d-Lua之table
- Lua之table
- lua的TABLE性质
- lua的table排序
- lua 的 table 处理
- lua的table排序
- lua的table排序
- lua table的使用
- lua table 的rehash
- lua 的table排序
- 系统备份软件的优势
- 课程设计 进制计算器
- 最初的梦想
- poj 2038 Team Rankings 枚举排列
- [Leetcode]-Same Tree
- Lua 之table的测试
- 读取系统配置文件
- 字符串指针与字符数组的区别(一)--字符串常量的值不能改
- 如何修改远程桌面的端口号
- 数据结构和算法系列 - FP-Tree算法的实现
- 移动终端基带芯片的基本架构介绍之二(移动终端中的基带芯片)
- c++中构造函数初始化的方法以及主要区别
- 内存拷贝和字符串拷贝
- hanoop的helloworld——WordCount解读