C # object method call from IronPython

I am trying to embed a script engine in my game. Since I am writing this in C #, I decided that IronPython would be a great option, but the examples I could find focused on calling IronPython methods in C # instead of C # methods in IronPython scripts.

To complicate matters, I am using Visual Studio 2010 RC1 on a 64-bit version of Windows 7.

IronRuby works as I expected, but I'm not very good at Ruby or Python syntax.

What am I doing:

        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);

This generates an error: "The TestClass object does not have the attribute" SayHello "

This fine tuning works fine with IronRuby, although "self.test.SayHello ()" is used

IronRuby, , , IronPython. , , .

? , - .

+3
2

... , , SayHello , , , SayHello, , Python .

+5

, , "" "", IronPython.

+1

Source: https://habr.com/ru/post/1737251/


All Articles