In a file called test.py
I have the following code:
def foo(callback):
callback(1, 2, 3)
def bar(x, y, z):
print x, y, z
When foo(bar)
is executed in the IronPython console, it outputs:
1 2 3
I want to call foo()
from a C# application. The following C# code executes foo()
, passing it a C# callback function.
var engine = Python.CreateEngine();
dynamic scope = engine.CreateScope();
engine.ExecuteFile("test.py", scope);
scope.callbackFunction = new Action<int, int, int>
((x, y, z) => Debug.Print("{0}\t{1}\t{2}", x,y,z));
scope.foo(scope.callbackFunction);
The output is:
1 2 1
I can't figure out why x == z
. Why is the C# output 1 2 1
instead of 1 2 3
? Am I sending it a C# callback function incorrectly?
I am running this on Windows 7, the C# application is targeted for .NET 4.5 and my IronPython version is 2.7.4.