I added Lua scripting to my C# Application by using the DynamicLua libary and it works very well. I would like to implement that you get the current line which is being executed (Like in Visual Studio) and highlight it.
Currently I am doing this:
public static void RunLua(string LuaToExecute)
{
dynamic lua = new DynamicLua.DynamicLua();
string[] lua_s_split = LuaToExecute.Split('\n');
int counter = 0;
foreach (string line in lua_s_split)
{
// highlight current line in editor
HighlightLine(counter + 1);
//execute current line
lua(line);
counter++;
}
}
This is working great with my Lua code like
move(20, 19)
sleep(1000)
move(5, 19)
but I cant only execute one line statements. Like my bound function move()
. But I would also like to use multiline statements like functions and loops. If the text editor contains:
function test()
return "Hallo Welt"
end
The lua(line)
will raise an exception because only the first line function test()
is passed and the interpreter is missing the end statement.
What can I do? Should I check if the line begins with an function,while... command and than scan for end blocks and add it to a string so I can execute and highlight this multiline statement all at one? Would this possible? How would I do it?
Please Help.
I would like to implement that you get the current line which is being executed (Like in Visual Studio) and highlight it.
Don't do this by feeding Lua the script a line at a time. Run the entire script and let Lua notify you when execution switches to a new line, via a debug hook:
Programming in Lua: Hooks
Lua manual: debug.sethook
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With