我对获取函数的任何返回格式感兴趣。例如Lua - 我如何获得任何回报?
function foo()
return 1
end
local result = foo() -- foo is numeric 1
function foo()
return {1,2,3}
end
local result1, result2, result3 = foo()
local result = foo() -- this is bad as result is `1` but `2` and `3` are lost
function foo()
return 1, 2, 3
end
local result = foo() -- foo is a table with all the numbers, that's ok
我建立一个分析器,这将覆盖功能与代理功能,但我需要知道返回的数据,然后检查它的type()
和访问accordingly`但是从代码可以看出,我无法使用一种方法访问所有3种情况。有没有 ?
@NicolBolas,因为我已经给了富的'三个例子()'函数应该清楚,我想抓住这三种情况下foo'的'。请不要在这里需要切线。 –
@NicolBolas谢谢你的帮助:)我已经更新了我的问题,我希望现在更清楚 –
所以你是这个函数的实际调用者。你打算检查这些结果,然后返回它们,就好像你是'foo'? –