[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.4.0 (beta) now available
- From: Tomás Guisasola <tomasguisasola@...>
- Date: Thu, 3 Oct 2019 16:17:17 -0300
Em qui, 3 de out de 2019 às 16:03, Jonathan Goble <email@example.com> escreveu:
> As for useful return values, the idiom in Lua has long been that functions which signal failure via return values return a falsy value and an error message on failure and "true" followed by the actual useful return values on success. As far as I could tell, that hasn't changed at all, so the first return value from such functions is merely a boolean indicator of success or failure and the useful data (on success) begins with the second return value.
Not exactly. The function io.open, for instance, does not return a
"true", just the actual file handler on success. On a failure, it
returns nil followed by an error message. IIRC, the two functions
that work the way you described are pcall and xpcall, since both are
very general functions. Note that if that was the protocol (always
return a boolean followed by the actual values), there would be no
reason to adopt a "fail" value, don't you think?