1
blocks = {block1 = {}, block2 = {}}

blocks.block1.x = 1
blocks.block1.y = 2

blocks.block2.x = 3
blocks.block2.y = 4

我想打印块表xy的每个项目,比如

for b in blocks do
    print(b.x)
    print(b.y)
end 

我知道块以这种方式最终成为局部变量,但我不知道任何其他解释方式。

基本上我想要输出

>
1
2
3
4
> 
4

1 回答 1

2

我不是专家,但你能试试这个吗?

for _, v in pairs(blocks) do
    print(v.x)
    print(v.y)
end

输出

1
2
3
4
于 2013-07-20T00:52:23.393 回答