使用函数中的表格条目进行关系表达式,而不需要额外的变量?

我想比较由函数返回的表格条目与固定字符串。如果我先将结果存储在变量中作为列表,则可以正常工作。 为什么不能作为一行表达式实现?有更好的方法吗?

-- 类似于 API 提供的函数
local testFunction = function()
    return true, {name = "hans"}
end

-- 正常工作
local a = {testFunction()}
if a[2].name=="hans" then
    --做一些事情
end

-- 不工作
if {testFunction}[2].name=="hans" then
    --做一些事情
end
点赞
用户14430048
用户14430048

添加括号解决了这个问题

if ({testFunction()})[2].name=="hans" then
    --do something
end

感谢 Egor Skriptunoff 的评论。

2020-10-13 15:41:15