【发布时间】:2011-01-28 09:08:36
【问题描述】:
我正在尝试在我的游戏中嵌入脚本引擎。因为我是用 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 那样成熟。如果它足够接近,我可能会去。
有什么想法吗?我知道这一定很简单。
【问题讨论】:
-
从 IronPython 调用 C# 方法对我来说效果很好。看不出您的 sn-p 有什么问题,也许可以将其完整发布,以便我们对其进行测试。我也使用 IronPython 和 IronRuby,IronPython 的稳定性要高 10 倍。如果你开始推送 IronRuby,你就会遇到问题。
标签: c# ironpython ironruby