lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 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.

The status in these other functions is there mainly because the normal
case can return any value, including "error" messages, not because error
objects can have any value.

> 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.

You mean calling the method without 'self'??

A nil as an error object seems quite unusual. By now, a quite simple
solution would be to "normalize" a nil to false when calling __close.

-- Roberto