lua-users home
lua-l archive

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

On Jul 14, 2008, at 2:24 PM, Ruan Kendall wrote:

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

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

I don't think you can assume this stack index will remain valid beyond the most local scope.  Perhaps your ERRERR is being called because the stack has changed since this line.

This is safer:

lua_pushcfunction(L, l_handle_error);
lua_setfield(L, LUA_REGISTRYINDEX, "l_handle_error");


then the pcall works like this:

lua_getfield(L, LUA_REGISTRYINDEX, "l_handle_error");
int ERROR_HANDLER = lua_gettop(L);

/* insert your code to push the function to call here */



at initialisation time. Pcalls from the C part of the system use this
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
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

Be seeing you

grrr waaa