lua-users home
lua-l archive

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


2014-10-20 8:34 GMT+02:00 steve donovan <steve.j.donovan@gmail.com>:
>
> Well, one option is: if the error is not a string, then try to call
> tostring() on it. Then we can have error objects with __tostring
> defined appropriately.
>
> 'nil' can either be a special case or simply an error, as Roberto suggests.
>
> steve d.
>

The manual says:

In case of unprotected errors in the script, the interpreter reports the error
to the standard error stream. If the error object is a string, the interpreter
adds a stack traceback to it. Otherwise, if the error object has a metamethod
__tostring, the interpreter calls this metamethod to produce the final message.
Finally, if the error object is nil, the interpreter does not report the error.

This seems to suggest that using debug.setmetatable to set __tostring for
nil might work — but it does not.