lua-users home
lua-l archive

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


On 28/02/2012, at 2:22 PM, Josh Klint wrote:

> I am looking for a way to call my own C++ function automatically at the end of each line in a Lua script.  The Lua SetHook function seems to do this:
> http://pgl.yoyo.org/luai/i/lua_sethook
> 
> However, the HOOK_MASKLINE function description has one giant caveat in its description:
> (This event only happens while Lua is executing a Lua function.)

What problem do you see with this caveat?  Is it that you would like to have your hook called after each line of code in a C function?

> I am not sure what this means, but the hook doesn't seem to get called in the manner I expect.

How, then, *does* the hook seem to get called?

> If I had a script like below, I would expect the hook to be called after executing each line:
> local a = 1 --hook executed!
> local b = a + 1 --hook executed!
> b = b + 2 --hook executed!
> 
> Is the functionality I want supported in Lua?

Yes.  This is what the line hook does (technically it's called *before* the line, but it's much the same).  Could you post some code?

Cheers,
Geoff