lua-users home
lua-l archive

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


Nodir Temirhodzhaev wrote:
> 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.

The Lua public API has been carefully crafted to avoid corrupting internal
data structures in this way. Another reason is the added flexibility in the
evolution of the Lua core (e.g. the addition of an incremental GC).

I have been hit by this restriction, too because I have the need to pass
arbitrary objects between different Lua universes (in the same process).
After some research, I guess I have to pass around proxies or just copies.
Not very efficient, but I found no better way. It is definitely hopeless
to make the GC cross-universe-aware to avoid the copying overhead.