lua-users home
lua-l archive

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


Oh gurus of the Lua Virtual Machine and debug hook system...

Some test code for me to understand the lua debugging hooks:

LINE 1: _G.aaa = 100
LINE 2: function foo()
LINE 3: 	_G.aaa = _G.aaa + 1
LINE 4: 	halt()
LINE 5: 	_G.aaa = _G.aaa + 1
LINE 6: 	_G.aaa = _G.aaa + 1
LINE 7: 	_G.aaa = _G.aaa + 1
LINE 8: end

In the halt() function (implemented in C), I set the hook mask to
LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE
and I begin to printf all the events I get.

I get a HOOKRET from inside halt(), with the calling function being foo(), LINE 4.
I'm happy so far.

The very next event I get is HOOKLINE with the current function being foo(), LINE 6. The value of _G.aaa is 102 (i.e. LINE 5 executed, but not LINE 6 yet)

I was expecting to get a HOOKLINE on LINE 5, with _G.aaa being 101 (since we wouldn't have yet executed LINE 5)

Is my expectation incorrect? Why does the VM not send me the HOOKLINE immediately after returning from a function? (This is executed on Lua 5)

The lua 5 ref manual says that the line hook is executed when the interpreter is about to start the execution of a new line of code... Shouldn't I have gotten a hook for LINE 5?

Thanks for any pointers or additional references!

-- Tim Gogolin