pcall可以返回被调用函数的返回值,而不仅仅是布尔值的真/假结果吗?

例如:

function f()
return 'some text'
end

print(tostring(pcall(f)))

print 语句只会显示 true 或 false,而不是 f 函数返回的值。

点赞
用户4261756
用户4261756
`tostring` 仅选择第一个参数。

a,b = pcall(f) print(b) --> 'some text'

```

2014-12-15 13:51:57
用户5644356
用户5644356

function f() return 'some text' end

local status, res = pcall(f)

```

如果_pcall_()成功,_status_为true,_res_是_f_()返回的值。 如果_pcall_()失败,_status_为false,_res_是错误消息。

2017-07-17 21:39:57