lua-users home
lua-l archive

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


I've defined a standard error handler, and use it like this...

lua_pushcfunction(L, l_handle_error);
ERROR_HANDLER = lua_gettop(L);

at initialisation time. Pcalls from the C part of the system use this
error handler.

lua_pcall(L, 0, LUA_MULTRET, ERROR_HANDLER)

Now, whenever a broken script is called, helpful error messages and
backtraces are displayed. But when pcalls are nested, the inner pcall
returns an ERRERR.

This occurs even when the error handler is effectively a NOP...

int l_handle_error(lua_State* L) { return 0; }

Now, am I using the error handler it a terribly bad way? I'm pretty
certain that the stack isn't overflowing, as a quick call to
lua_gettop after the pcall has returned shows the stack as having 3
elements in it. Unless I totally misunderstand gettop, too.

 - Ruan

On Mon, Jul 14, 2008 at 4:38 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Under normal circumstances, it works just fine. However, under certain
>> circumstances (I'm not totally sure what all of these are yet) such as
>> C pcalls a lua script which calls a C function which pcalls a faulty
>> lua script, the error handler breaks. [...]
>
> Your error handler is for which pcall, the first or the second? And which
> pcall gives the ERRERR error?
>
>
>> I'm not entirely certain under what circumstances ERRERR is returned,
>> and I haven't been able to gather this information from reading the
>> lua source.
>
> ERRERR is returned when there is an error while running the error function.
> That is, there is some error that triggers the error function, and then
> there is another error in the error function itself.
>
> -- Roberto
>