lua-users home
lua-l archive

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


It was thus said that the Great Ranier Vilela once stated:
> You mean don't have to call lua_pop?

  It depends upon the code.  

> I have a bug reading an invalid pointer, in an adjacent library, which I'm
> not sure is caused by Lua gc.

  It may be an issue over who owns the memory for the userdata, but without
knowing the exact error, it's hard to say.

  Here's a function (for Lua 5.2+) that I use to debug Lua stack issues:

static int cstack(lua_State *L)
{
  int max = lua_gettop(L);
  
  fprintf(stderr,"Stack dump\n");
  
  for (int i = 1 ; i <= max ; i++)
  {
    fprintf(
            stderr,
            "%d %d - %s %s\n",
            i,
            i - max - 1,
            luaL_typename(L,i),
            luaL_tolstring(L,i,NULL)
    );
    lua_pop(L,1);
  }
  
  fprintf(stderr,"Stack done\n");
  return max;
}

  I wil add calls to this funciton at points where I want to know what's on
the stack, and at what index (this will print both positive and negative
indecies).

  -spc (Hope this helps)