skynet.select中table.unpack的使用结果是未定义的 #2142
dingdalong
started this conversation in
General
Replies: 1 comment
-
|
如果需要在参数中包含 nil , 需要用 table.pack 打包,或者主动提供 .n 。严格来说,select 的 api 要求你传入一个不包含 nil 的数组或提供 .n 限定数组的长度。test 中并未传入 nil 。 这一点在 5.4 中也一样,并非 5.5 改变了行为。Lua 对包含 nil 的数组从来都是未定义的。 如果你想包含其它项,比如这里的 token ,那么应该先用 table.pack ,然后给 token 赋值。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
在新版本(升级
lua5.5)中如果调用参数中出现nil,会导致参数截断skynet/lualib/skynet.lua
Line 209 in c2150ba
这里展开
table依赖的是table.unpack,要求传入参数使用table.pack打包,这样才有n值。skynet/test/testselect.lua
Line 52 in c2150ba
用例中,全部都是用
{}的方式构造的table。还支持传入token这样的参数。这会导致
unpack的结果是未定义的。只是在lua5.4之前返回的参数个数是预期的,升级到5.5之后就不行了。
最简单的例子:
print(#{1,2,nil,4,5,token=1}),在5.4中打印5,5.5中打印2。Beta Was this translation helpful? Give feedback.
All reactions