lua-users home
lua-l archive

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


I think, as suggested by Rici, that you need a table mapping C++
pointers to userdata in the Lua userdata's metatable.  somehow you'll
need to get the lua_State.  In this case, I assume a pointer is cached
in the cpp_class and that the table of cpp pointers to userdata is in
the metatable's "instances" field;

pseudo code

callback(cpp_class *c)
{
   lua_State *L = c->lua();
      luaL_getmetatable(L, cpp_class::metatable_name);
      lua_pushstring(L, "instances");
      lua_gettable(L, -2)
      lua_pushinteger(L, (int)c);
      lua_gettable(L, -2)
      //either nil or your userdata will no be on the stack
}


Also I would make the "instances" table a weak table with __mode = "v"

wes