lua-users home
lua-l archive

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


> > LUA_API void lua_pushtable (lua_State *L, const void *t) {
> >   lua_lock(L);
> >   sethvalue(L->top, t);
> >   api_incr_top(L);
> >   lua_unlock(L);
> > }
> 
> This doesn't work and will severly screw up the garbage collection.
> 
> In general you cannot store any mutable object in your own structures.
> If there is no other reference to it then the garbage 
> collection will silently free it. If you later try to restore 
> it, you give the Lua core an invalid pointer and bad things 
> will happen.

If you can use C++, LuaPlus's (http://luaplus.org/) LuaObject properly
stores Lua objects in data structures that can reside on the stack or as
member variables AND get properly added to the garbage collection pass.  It
modifies the Lua core a bit to do this, but it may be to your benefit.

Josh