Thanks, that's exactly what I needed!
Through some experimentation I found out that each coroutine has its own lua_State * associated with it in the C environment. So, all I'll probably need is to use your code below to signal to the C environment a new thread is created, with the associated lua_State pointer. Then I can also make the debugger tell the user what thread we are in. Thanks a lot.
Per
----- Original Message ----
From: Eike Decker <zet23t@googlemail.com>
To: Lua list <lua@bazar2.conectiva.com.br>
Sent: Tue, January 26, 2010 3:50:55 PM
Subject: Re: Debugging coroutines
You can attach your debug hooks to coroutines, and you have to do this
with all known coroutines in your lua state to make it work. Otherwise
it will just do what you notice - ignoring code being executed from a
coroutine.
I also cursed at this behavior sometimes and wished that there was a
simple way to attach debug hooks not only to a coroutine but to the
entire lua state, catching everything at once (or is it possible?).
But luckily, it can be fixed in Lua:
local cocreate = coroutine.create
function coroutine.create (...)
local ret = {cocreate(...)}
-- do something with the coroutine at ret[1], like attaching your hooks
return unpack(ret)
end
Eike