lua-users home
lua-l archive

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


The function I'm proposing is very simple, though it does require an addition to the Lua core. Here's what I added to lapi.c:

LUA_API lua_State *lua_getmainthread (lua_State *L) {
 lua_State *L1;
 lua_lock(L);
 L1 = G(L)->mainthread;
 lua_unlock(L);
 return L1;
}

I don't know if the calls to lua_lock and lua_unlock are truly necessary, but I figured I'd be on the safe side. Adding this API function has at least one advantage over storing the main state in the registry: with this API function, any library can obtain the main state without requiring the host application to do any special initialization. Libraries such as LuaCOM can then take advantage of this feature; in fact, I'm about to modify my copy of LuaCOM to do so.

--
Matt Campbell
Lead Programmer
Serotek Corporation
www.freedombox.info
"The Accessibility Anywhere People"