lua-users home
lua-l archive

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


On Tue, Feb 4, 2020 at 8:02 PM nobody wrote:
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

-- create a separate coroutine
local co = coroutine.create(
   function()
      local function Func() end
      Func()
   end
)

-- 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
)

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