lua-users home
lua-l archive

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

Ignacio Burgueño wrote:
David Burgess wrote:
Can you add

 lua_State* mL= luaL_getmainthread(L); // returns the main lua state

to the list?

I second that. Also, at the moment, checking if a thread is the main one is a little cumbersome (i.e. pushthread, checking the return value and then poping the thread). luaL_getmainthread would allow for an easy equality test.

Thirdsies! It's the only thing we add to ourselves, even though we're using Lua for large projects. With "lua_" instead of "luaL" though. Wouldn't it be more something of a core function?

To elaborate: we're using it to make sure a wrapper class for Lua refs works correctly. A reference wrapper class stores a pointer to the Lua *main* state (using the custom lua_getmainthread call) so it can free the reference on demand when the class destructor is called. If you store any Lua state, you might store a pointer to a thread that could already deleted when the destructor of the reference wrapper class is called, causing a crash. lua_pushthread doesn't help us in this case.

Kind regards,

Daan Nusman, M.Sc.
+31 53 4356687