gpt4 book ai didi

c# - 逐行编写Lua脚本

转载 作者:太空狗 更新时间:2023-10-30 00:51:55 25 4
gpt4 key购买 nike

我使用 DynamicLua 将 Lua 脚本添加到我的 C# 应用程序中库,它工作得很好。我想实现您获取正在执行的当前行(就像在 Visual Studio 中一样)并突出显示它。

目前我正在这样做:

   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++;
}
}

这对我的 Lua 代码非常有效,例如

move(20, 19)
sleep(1000)
move(5, 19)

但我不能只执行一行语句。就像我的绑定(bind)函数 move()。但我也想使用多行语句,如函数和循环。如果文本编辑器包含:

function test()
return "Hallo Welt"
end

lua(line) 会抛出异常,因为只有第一行 function test() 被传递,解释器缺少结束语句。

我能做什么?我是否应该检查该行是否以函数开头,而...命令,而不是扫描结束 block 并将其添加到字符串中,以便我可以一次执行并突出显示此多行语句?这可能吗?我该怎么做?

请帮助。

最佳答案

I would like to implement that you get the current line which is being executed (Like in Visual Studio) and highlight it.

不要通过一次给 Lua 脚本一行来做到这一点。运行整个脚本并让 Lua 在执行切换到新行时通过调试 Hook 通知您:

Programming in Lua: Hooks
Lua manual: debug.sethook

关于c# - 逐行编写Lua脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24334574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com