感谢来自previous question的建议,我正忙于尝试IronPython,IronRuby和Boo为我的C#应用程序创建DSL。由于更大的用户和知识库,第一步是IronPython。如果我能在这里得到一些好的工作,我可以停下来。使用IronPython简化为C#应用程序编写的DSL
这里是我的问题:
我希望我的IronPython的脚本访问的功能在一个名为库类。现在我可以组装添加到IronPython的运行时间,并在我创建的范围内执行该语句导入类:
// load 'ScriptLib' assembly
Assembly libraryAssembly = Assembly.LoadFile(libraryPath);
_runtime.LoadAssembly(libraryAssembly);
// import 'Lib' class from 'ScriptLib'
ScriptSource imports = _engine.CreateScriptSourceFromString("from ScriptLib import Lib", SourceCodeKind.Statements);
imports.Execute(_scope);
// run .py script:
ScriptSource script = _engine.CreateScriptSourceFromFile(scriptPath);
script.Execute(_scope);
如果我想运行库:: PrintHello,这仅仅是一个Hello World风格声明,我的Python脚本包含:
Lib.PrintHello()
或者(如果它不是静态的):
library = new Lib()
library.PrintHello()
我怎样才能改变我的环境,这样我就可以有基本的statments像THI的Python脚本s:
PrintHello
TurnOnPower
VerifyFrequency
TurnOffPower
etc...
我希望这些脚本对非编程人员来说很简单。我不希望他们必须知道什么是课堂或课程是如何运作的。 IronPython实际上就在那里,所以像一些基本的操作,如果和一个基本的函数定义不需要我为我的DSL编写编译器。
它在IronRuby的,我不得不写 脚本库:: Lib.PrintHello看起来更加丑陋() 是任何人都熟悉或者IronRuby的或IronPython的这种方式?在运行测试脚本之前,我需要一个python安装脚本来映射所有方法/变量吗?我曾希望在C#中做到这一点。 – cgyDeveloper 2009-08-28 21:20:22