我正在尝试在我的游戏中嵌入一个脚本引擎。由于我是用C#编写的,我想IronPython会非常适合,但我找到的示例都集中在从C#调用IronPython方法而不是在IronPython脚本中调用C#方法。
为了复杂化事情,我正在使用Windows 7 64位上的Visual Studio 2010 RC1。
IronRuby的工作方式符合我的预期,但我对Ruby或Python语法不是很熟悉。
我正在做什么:
为了复杂化事情,我正在使用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那样成熟。如果足够接近,我可能会选择它。
有什么想法吗?我知道这一定是很简单的事情。