[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: debug hook for line mode works odd
- From: Igor Munkin <imun@...>
- Date: Thu, 31 Mar 2022 18:18:56 +0300
Hi folks,
I've recently faced an example of debug hooks odd behaviour. I've
checked both reference manual and actual implementation for Lua versions
from 5.1 to 5.4 and have failed to understand the following output:
| $ lua -e 'debug.sethook(function(_, l) print("LINE: "..l) end, "l") load("\n\ns=nil")() s=nil debug.sethook()'
| LINE: 3
According to reference manual[1] the line hook is called when the
interpreter is about to start the execution of a new line of code, or
when it jumps back in the code (even to the same line). This event only
happens while Lua is executing a Lua function.
The function created by <load> is actually Lua function. AFAIU *return*
from the mentioned function is actually "a jump back in the code".
Hence, the expected output is the following:
| LINE: 3
| LINE: 1
I see only two options:
* There are some inconsitencies between reference manual and implementation
* PEBKAC, i.e. the problem is on my side (then I'm asking for help with
reading reference manual).
[1]: https://www.lua.org/manual/5.4/manual.html#lua_sethook
--
Best regards,
IM