pcall可以返回被调用函数的值而不是布尔结果的真/假吗?
例如
function f()
return 'some text'
end
print(tostring(pcall(f)))
Run Code Online (Sandbox Code Playgroud)
print将仅显示true或false,而不是f返回的值
das*_*das 15
tostring只选择第一个参数.
a,b = pcall(f)
print(b) --> 'some text'
Run Code Online (Sandbox Code Playgroud)
function f()
return 'some text'
end
local status, res = pcall(f)
Run Code Online (Sandbox Code Playgroud)
如果pcall ()成功,则status为true,res为f ()的返回值。如果pcall () 失败,则status为 false,res为错误信息。
| 归档时间: |
|
| 查看次数: |
4392 次 |
| 最近记录: |