lua-users home
lua-l archive

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

> -----Original Message-----
> From: [] On
> Behalf Of Roberto Ierusalimschy
> Sent: zaterdag 6 april 2013 15:12
> To: Lua mailing list
> Subject: Re: question on debug hooks
> > Especially with values "l" and 50000, I would have expected the debug
> counter to be far lower than the loop counter.
> > What am I missing? Any help is appreciated.
> *
>    With a count different from zero, the hook is called after every
>    count instructions.
> "instructions" here means opcode instructions of the virtual machine.

I read that and already figured it would be opcode instructions. But in the case when a number is provided, the mask is ignored, but still checked. From what I read I tried a nil value for mask, but that failed with a "string expected" error.

If I understand it correctly, couldn't the api be simpler with behavior like this;

local sethook = debug.sethook
debug.sethook = function(coro, mask)
  if tonumber(mask) then
    return debug.sethook(coro, "", mask)
    return debug.sethook(coro, mask)

Under all circumstances only parameter (either mask or count) is used, so why have 2?

And imo the following would be clearer for the manual;
    With a count different from zero, the hook is called after every
    count instructions (compiled opcode instructions). Mask must still 
    be a string, but will be ignored.

> So, with values "l" and 50000, the hook is called for every line and for
> every 50000 instructions executed. Each line in your loop has less than a
> dozen instructions, so the line calls completely dominates the counting.

That makes sense.