lua-users home
lua-l archive

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


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

2010/1/26 Per Bull Holmen <pbholmen@yahoo.com>:
> Hi
>
> How would one go about to make a debugger which works on coroutines in Lua?
>
> I am completely new to Lua, but pretty OK at C. I wanted to make a simple debugger for Cocoa (MacOS X), so that if you make a program which executes custom lua scripts, those scripts can be debugged with a debugger inside the program (rather than using an external IDE). I'm not writing the debugger in lua, but in Objective-C (just think of it as C), and it's supposed to be called from C, not from Lua. I have used the documentation found here:
>
> http://www.lua.org/manual/5.1/manual.html#3.8
>
> It is Lua 5.1 I'm using. The debugger works fine, but when a coroutine is called, the debugger can't step through the lines in the function that the coroutine calls/executes. When my hooks are called, all the information I get is that I'm inside a C function called "resume". Is it feasible to do what I'm trying to do? Do I have to write some code inside the Lua environment to make it work? Currently it's all pure C/Objective-C, not even callable from Lua.
>
> I'm also waiting for the newest copy of Programming In Lua in the mail. If the answer is in that book, I'm sorry... :)
>
> Per
>