Lua脚本逐行 [英] Lua scripting line by line

查看:769
本文介绍了Lua脚本逐行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加Lua脚本到我的C#应用​​程序使用 DynamicLua libary,它工作得很好。
我想实现你得到正在执行(就像在Visual Studio)当前行,并强调它



目前我这样做:

 公共静态无效RunLua(字符串LuaToExecute)
{
动态卢阿=新DynamicLua.DynamicLua() ;

的String [] = lua_s_split LuaToExecute.Split('\\\
');
INT计数器= 0;
的foreach(在lua_s_split串线)
{
//突出编辑
HighlightLine当前行(计数器+ 1);

//执行当前行
LUA(线);
计数器++;
}
}

这好像是伟大的工作与我的Lua代码

 移动(20,19)
睡眠(1000)
移动(5,19)

但我不能只执行一行语句。就像我的绑定功能移动()。但我也想用多行语句像功能和循环。如果文本编辑器包含:

 功能测试()
返回喂世界报



LUA(线)将引发异常,因为只有第一行功能测试()传递和解释缺少结束声明。



我可以做?我应该检查是否符合一个功能开始,而...命令,比扫描结束块,并把它添加到一个字符串,所以我可以在同一执行,并强调这多行语句中的所有?请问这可能吗?我会怎么做呢?



请帮助。


解决方案

我想实现你得到正在执行(就像在Visual Studio),并突出显示当前行。




别ŧ喂养的Lua脚本在一个时间线做到这一点。运行整个脚本,让Lua的通知您何时执行切换到新的生产线,经调试挂钩:



在Lua编程:钩结果
Lua的手册:debug.sethook


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

这篇关于Lua脚本逐行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆