lua-users home
lua-l archive

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



Please ignore my last message, for some reason gdb was not telling
me the correct location of the crash. Once I had the correct location
it was clear I had messed the stack up.
Many apologies!


I have a problem: when I call lua_touserdata() on a file pointer
in the io table I get a bus error.

I'm doing this because I need to go through all variables and do something for any I find that are of a particular userdata type (using C++).

I have this working pretty much, I start at _G, recurse through everything and when I find userdata I do this:

     if ( lua_type(L,-1) == LUA_TUSERDATA ) {
        int *ud =(int *) luaL_checkudata_noerror(L, -1, utype);
        if (ud != NULL) {

Where luaL_checkudata_noerror is just a copy of luaL_checkudata from
the auxlib with the bit that generates a error if the type is wrong
commented out, the start looks like:

LUALIB_API void *luaL_checkudata_noerror (lua_State *L, int ud, const char *tname) {
  void *p = lua_touserdata(L, ud);

^that's the line that gives the bus error, when it is called with
one of the file pointers.

I think it may have something to do with the environment of the userdata? But I'm not sure how to fix it.

Alternatively, if there was a way to avoid recursing into the library stuff without having a list of things to skip (which is my current workaround), that would be nice too.

thanks,
Costas