Lua scripting line by line

我是研究僧i 提交于 2019-12-05 12:19:21

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

[EDIT] At the time of this answer, I was unaware of the LUA parser mentioned in the accepted answer. I am agreed with that poster that you should use official parsing libraries wherever possible rather than rolling your own. The below answers the original question, but should not be seen as the ultimate answer. Please view the accepted answer for the correct method to handle this problem.[/EDIT]

You're explicitly calling it to parse the line of code / execute the LUA.

If you have a multiline function, ensure you're passing the full thing before calling the execution block.

var myCommand = new StringBuilder()

... myCommand.Append(line) ...

foreach (string line in lua_s_split)
    {
        // highlight current line in editor
        HighlightLine(counter + 1);

        //execute current line 
        If(NeedsToExecute(istrue))
        {
            lua(myCommand.ToString());
            counter++;
        }
        else{myCommand.appendline(line)
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!