lua-users home
lua-l archive

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


Hello RLake,

Wednesday, April 28, 2004, 6:05:49 PM, you wrote:

Thank you very much!

Roop> Not quite right. luaL_ref takes a table index as its
Roop> second argument; that is the table in which the references are stored,
Roop> and is the same table which luaL_unref must be given as a second argument.
Roop> Typically LUA_REGISTRYINDEX is used as the table index, but you could use
Roop> a table of your own.

Roop> luaL_ref(L, t) pops the top stack object and returns
Roop> a reference index (which is an integer key into the table at t).
Roop> luaL_unref(L, t, idx) deletes the object with index
Roop> idx from the table at t. It does not change the stack.

Roop> So:

Roop> // Creating thread
Roop> m_thread           = lua_newthread(L);
Roop> m_thread_reference = luaL_ref(L, LUA_REGISTRYINDEX);

Roop> // Releasing thread, whether finished or yielded
Roop> luaL_unref(L, LUA_REGISTRYINDEX, m_thread_reference);

-- 
Best regards,
 Dmitriy                            mailto:iassenev@gsc-game.kiev.ua