[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Finding the main thread?
- From: M Joonas Pihlaja <jpihlaja@...>
- Date: Sat, 13 Feb 2010 21:57:55 +0200 (EET)
It appears to me that there's no way a user of the lua C API can find
out what the main thread of a lua_State is. The lua_pushthread()
function helpfully says if the current thread is the main thread, but
that's about the extent of what the manual has to say on the subject
that I could find.
If it's not possible in Lua 5.1, could Lua 5.2 include this
functionality please? My use case is: I'm wrapping a library which
doesn't provide a "userdata" pointer for its callback functions. To
inform my C->Lua gateways of the lua_State they should look for their
Lua counterparts in I'm using a global lua_State. My problem is that
if the user actually set the Lua function callback to call from within
a coroutine instead of the main Lua state, and that coroutine goes
away before the callback gateway is called, then *boom* I've got a
stale lua_State pointer.
My alternate safe solution is to store the current lua_State in a
global at every Lua -> C boundary, but that's a much more invasive
change to my wrapper code unfortunately.