我正在尝试在我的游戏中嵌入脚本引擎。因为我是用 C# 编写的,所以我认为 IronPython 非常适合,但是我能够找到的示例都集中在调用 IronPython 中的 C# 方法而不是 IronPython 脚本中的 C# 方法。
更复杂的是,我在 Windows 7 64 位上使用 Visual Studio 2010 RC1。
IronRuby 像我预期的那样工作,但我对 Ruby 或 Python 语法不是很熟悉。
我在做什么:
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
//Test class with a method that prints to the screen.
scope.SetVariable("test", this);
ScriptSource source =
engine.CreateScriptSourceFromString("test.SayHello()", Microsoft.Scripting.SourceCodeKind.Statements);
source.Execute(scope);
这会产生一个错误,“'TestClass' 对象没有属性 'SayHello'”
尽管使用“self.test.SayHello()”,但这个确切的设置在 IronRuby 上运行良好
不过,我对使用 IronRuby 持谨慎态度,因为它看起来不像 IronPython 那样成熟。如果它足够接近,我可能会去。
有任何想法吗?我知道这一定很简单。