Code stepping in Lua
[color=#000000][font=Helvetica]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:[/font]
10x Faster Performance for VR: www.ultraengine.com
I'm no Lua expert, and this might have bad performance issues, but why not load your lua script like you'd load a normal text file, break it up into lines, and execute each line with luaL_dostring. Inbetween each luaL_dostring() call, you can run whatever C++ code you like. You could wrap the entire thing in a function taking a callback, if that's what you want. (MyLuaDoFile(scriptFile, myCallback()).
For optimization, if you routinely run the same lua script, you might want to pre-load and pre-compile the script portions using luaL_loadstring (I'm guessing - I've never done it before), to reduce the overhead of parsing the data before running it.
For optimization, if you routinely run the same lua script, you might want to pre-load and pre-compile the script portions using luaL_loadstring (I'm guessing - I've never done it before), to reduce the overhead of parsing the data before running it.
At work we use Tilde, which does use these hooks to implement its line-by-line debugger, so yeah it should be possible for you to receive a callback for each line of code the VM runs.
However, the LUA_MASKLINE function description has one giant caveat in its description:
This event only happens while Lua is executing a Lua function.
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.)[/quote]To me, that caveat sounds like it's implying that when Lua calls into a C function, no callbacks will be triggered, but when it returns from the C function, it will.
. 22 Racing Series .
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement