lua-users home
lua-l archive

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


Hi Egor,

>> And it also won't work if you want to use debug hooks on a separate
>> coroutine (e.g. abort after N instructions or on any attempted
>> call, for safely un-dumping some values).

> I can't reproduce your problem.
> The following code works fine for me.
> Tested on both vanilla Lua and LuaJIT 2.1

Maybe it was meant to emphasize that LuaJIT debug hooks are global
(whereas Lua hooks are per coroutine):
https://luajit.freelists.narkive.com/lexU9r0S/debug-hooks-and-jit

LuaJIT will accept co as the parameter, but ignores it as far as I can
tell. If you slightly tweak your example, you can see that the hook is
called during the standalone FuncMore() call in LuaJIT, but not in
Lua:

-- create a separate coroutine
local function FuncMore()
  local function Func() end
  Func()
end

local co = coroutine.create(FuncMore)

-- set hook on the separate coroutine
debug.sethook(co,
  function(event)
    local info = debug.getinfo(co, 2, "n")
    local func_name = info and info.name or "?"
    print(event, func_name)
  end,
  'cr'  -- on function call and return
)

FuncMore()

-- run the separate coroutine
coroutine.resume(co)

Paul.