lua-users home
lua-l archive

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

> What is the simplest way in LuaJIT to determine
> which coroutine the hook was invoked in?

You can call `coroutine.running()` to get the current coroutine (or
the "main" thread).

> Is it a good suggestion to add global hooks to Lua?

I'm not sure. Mike indicated in the thread I referenced that the
global hook has some advantages, but from the debugger perspective
it's advantageous to be able to only set hook on some of the "threads"
(instead of checking if it needs to be "enabled" for a particular
thread, which is what I ended up doing in mobdebug for luajit).

If I had a choice, I'd rather focus on integrating OP_HALT and
on_error hooks into the interpreter to provide better/faster debugger.
I'd love the ability to restart after an error (let's say it errors
out on `a+1` because `a` is `nil`, but the debugger allows the user to
assign `a` value and continue from the same command). This doesn't
solve the problem of a mistyped variable, so ideally the user should
be able to edit/recompile the currently running context, but it's a
much harder problem, so just being able to run a hook after an error
and restart from the same position may be sufficient for many
interesting scenarios.