lua-users home
lua-l archive

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


Hello,

after considering the lua_WarnFunction further points came up for me:


- It is not possible to change the behavior from within Lua. If I was
running a Lua program using the standard interpreter and I don't want
random outputs from warnings to stderr, I would have to load a C-module.


- Writing a custom lua_WarnFunction I have to be extremely careful that
the output function wouldn't trigger events that call Lua code again, as
the state is still locked.

For example, I might call the MessageBox function in Windows which opens
a modal dialog. While the dialog is open, if I am not mistaken, events
like drawing requests and timers would still get dispatched to other
windows of the application, which might call Lua code again. Yes, there
are solutions to avoid that, but it quickly gets complicated.


- It is not clear to me when a script could be expected to call the
"warn" function.

In the Lua core the warn function is something very serious only called
when an error happens that cannot be dealt with. Almost like a call to
the panic function. But when would a normal Lua script get into the
situation that it couldn't call "error"?

I am afraid that the warn function, based on its name, might get used in
libraries as an "almost-error" more for debugging purposes even though
it is much more difficult to handle properly in many applications.


Maybe it would be possible to provide a normal Lua callback for GC
errors? After all, the Lua __gc metamethod function was called just
prior to it.

Best regards,

David