[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: __close and nil error
- From: Lars Müller <appgurulars@...>
- Date: Sun, 25 Sep 2022 15:34:12 +0200
Another possible solution would be to pass no value as second argument
to __close. Functions with a signature of function(value, error) will
continue to work, since "no value / none" will automatically be
converted to nil. Functions with a signature of function(value, ...)
could however use select("#", ...) == 0 to check whether none or nil was
passed. The only downside to this would be that it kind of abuses
varargs, which is also somewhat slower than using regular arguments.
On 25.09.22 14:51, John Belmonte wrote:
I noticed a possible issue of the __close metamethod: nil is a valid
value for raising errors, but __close cannot distinguish between nil
error and no error.
Other functions passing errors (pcall, etc.) seem to use a status +
err tuple, so the cases can be distinguished.
Since the manual says "nil and false are ignored as to-be-closed
values", I wonder if the first arg of __close can be overloaded to
convey the error case, by the value false, which otherwise can't happen.