我對獲取函數的任何返回格式感興趣。例如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'? –