lua-users home
lua-l archive

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


I think it would be useful to have a C API function called lua_getmainthread which returns the lua_State of the given state's main thread. I can think of two uses for this function. It allows C code to determine whether two lua_State pointers belong to the same global state. More importantly, C code which needs to receive a lua_State from Lua and store it long-term for use by callbacks can use this function to make sure it has a lua_State that isn't about to go away. Without this measure, C functions called from a short-lived coroutine get a lua_State pointer that will soon become invalid.

This lua_getmainthread function would be very easy to implement; it only needs to return the mainthread member of the state structure. I'll probably go ahead and implement it in my copy of Lua (5.1 final). I'm posting this suggestion because I figure it would be generally useful. Any thoughts?

Matt Campbell
Lead Programmer
Serotek Corporation
"The Accessibility Anywhere People"