lua-users home
lua-l archive

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

Are you using Lua 5?
I know that there is a bug in Lua 5 that HOOKLINE is not reliably called at the expected times. Luiz posted on Aug 13 that this bug was fixed in Lua 5.1, but I have not verified that.

Not sure if this is related to HOOKCALL/HOOKRET reliability.

-- Tim Gogolin

On Sep 17, 2004, at 4:10 PM, Tom Spilman wrote:

 So i have a little code that figures out the current stack level...

	int lbserver::_get_stack_level( lua_State* L )
		lua_Debug info;
		memset( &info, 0, sizeof( info ) );
		int levels = 0;
		while ( lua_getstack( L, levels, &info ) == 1 ) {

		// returns 0 if we're at the bottom of the
		// stack and levels - 1 for the top.
		assert( levels > 0 );
		return levels - 1;

I use this when a client initially connects to the debug server. Every thing worked great until I switched from my test script to a bigger embedded lua app. My hook would sometimes generate negative stack levels, so I added
in an assert and found that at times the stack level doesn't match my

	if ( ar->event == LUA_HOOKCALL ) {


		// This should never fail... but does!
		assert( _level == _get_stack_level( L ) );

	} else if ( ar->event == LUA_HOOKRET ||
			ar->event == LUA_HOOKTAILRET ) {
		// This should never fail... but does!
		assert( _level == _get_stack_level( L ) );


Currently I have this happening from within a tail call, so I guess I don't really understand how they work. Isn't a call stack from within a tail call still supposed to include the caller? If not how does a debugger properly
report a call stack for tail calls?

  Tom Spilman
  Co-owner | Programmer