今天看了下lua的pdf。学习了一下lua。
对于表:看一下代码:
polyline = {
color = "blue", thickness = 2,
{ x = 0, y = 0 },
thicknesss = 10,
{ x = -10, y = 0 },
{ x = 0, y = 1 }
}
print( polyline[ 2 ].x );
print( polyline.color );
print( polyline.thicknesss )
代码是这样的,可运行结果出乎我的预料:
怎么也没想到print( polyline[ 2 ].x );输出的居然是-10.
原来,它会按照类型分一个是
假设 a = {
{ x = 0, y = 0 },
{ x = -10, y = 0 },
{ x = 0, y = 1 }
}
一个是
b = {
color = "blue", thickness = 2, thicknesss = 10,
}
如果你输出[x],则去a里面找,下标从1开始,(切记lua下标从1开始),如果是polyline.color或者polyline.thickness或者polyline.thicknesss则去b里面找!!!
(不过lua中,一行代码尾部可以不要“;”号,着实让人很蛋疼,动不动就让人敲上去了,对于我这个菜鸟来说,额,得慢慢适应!!!)
时间: 2024-10-24 11:44:26