【发布时间】:2023-03-28 02:30:01
【问题描述】:
我的理解是pairs(t) 只是返回next, t, nil。
如果我将其更改为 next, t, someKey(其中 someKey 是我表中的有效键),next 会在该键处/之后开始吗?
我在Lua Demo 页面上试过这个:
t = { foo = "foo", bar = "bar", goo = "goo" }
for k,v in next, t, t.bar do
print(k);
end
每次运行代码时都会得到不同的结果。所以指定一个起始键是有效果的,不幸的是这个效果似乎有点随机。有什么建议吗?
【问题讨论】:
-
pairs也会随机迭代哈希图。
标签: lua iterator next lua-table