lua-users home
lua-l archive

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

You might find you need to do something similar with coroutine.wrap as well.

Per Bull Holmen wrote:
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.


----- Original Message ----
From: Eike Decker <>
To: Lua list <>
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
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)



Dave Nichols
Match-IT Limited
Tel: 0845 1300 510
Fax: 0845 1300 610

Email Disclaimer: The contents of this electronic mail message and any attachments (collectively "this message") are confidential, possibly privileged and intended only for its addressee ("the addressee"). If received in error, please delete immediately without disclosing its contents to anyone. Neither the sender nor its management or employees will in any way be responsible for any advice, opinion, conclusion or other information contained in this message or arising from it's disclosure.