【发布时间】:2021-12-24 22:43:51
【问题描述】:
我目前正在评估我的 .NET 应用程序的脚本选项。用户应该能够编写脚本(在应用程序内的专用文本/代码编辑器中)来控制应用程序本身。该应用程序完全用 C# 编写。作为我目前正在评估的脚本语言
- LUA
- 铁蟒
我找到了以下文章 (https://www.cyotek.com/blog/adding-scripting-to-net-applications),它依赖于 JavaScript,这也是一种选择。目前,我不清楚如何提供应用程序中使用的内部对象以及所用脚本的自定义函数。上面的链接依赖于 JINT(.NET 的 Javascript 解释器),它提供了为脚本添加自己的方法和对象的方法:
protected virtual void InitializeEnvironment()
{
this.AddFunction("print", new Action<object>(this.WriteLine));
this.AddFunction("log", new Action<object>(this.WriteLine));
this.AddFunction("cls", new Action(this.ClearScreen));
// interactive functions
this.AddFunction("alert", new Action<object>(this.ShowAlert));
this.AddFunction("confirm", new Func<object, bool>(this.ShowConfirm));
this.AddFunction("prompt", new Func<object, object, string>(this.ShowPrompt));
}
我没有找到使用 IronPython 的方法 - 至少文档中没有提到它,并且没有这种方法的示例。也许我在这里完全走错了路 - 任何帮助/提示都会很棒。
【问题讨论】:
-
第三个选项:使用
CSharpCodeProvider的 C# 脚本。 -
你可以用
NLua添加Lua脚本 -
@Egor 是的,我知道,但在这里我遇到了同样的问题。如何添加自己的方法和对象...
-
RegisterTableFunction
标签: c# lua scripting ironpython