Sign in to follow this  
ZachMeyer

[XNA/IronPython] Invoking delegates from IronPython

Recommended Posts

Hello everyone! I am currently in the process of creating an all-in-one 2D game framework designed on XNA using .NET 3.5 and C# 3.0. Aside from the hard-coded interface, I am also offering the ability to create the game in IronPython as well. BACKGROUND INFO: So far, my scripting engine (which interacts with IronPython) has been able to reproduce every single example I have cooked up so far using my framework including window creation, sprite rendering, etc. The way I have designed by InputManager is so that users can assign a Key to a Dictionary object, and also assign a delegate process to that key which will be invoked whenever the key is pressed. HELP NEEDED: In the hard-coded method, the input manager works flawlessly, but the IronPython interface does not seem to have any way of assigning delegates which is posing a problem via writing your input code in IronPython. Does anyone have any clue on how to invoke delegates from IronPython? PS: I have been searching google for hours (literally), no luck there.

Share this post


Link to post
Share on other sites
What exactly is not working? Cause I was both creating a delegate in Python and executing one:
public delegate void MyDelegate(string msg);
public void Test(MyDelegate del)
{
del("Ala");
}

public MyDelegate Test2()
{
return new MyDelegate(WriteLine);
}

In IronPython:

def MyFun(str): print str;
Test(MyFun) //works

d = Test2() //works
d("Ala") //works

SomeEvent += MyFun //works


Try also this one: "We can create a delegate from a Python function using the IronPython.Runtime.Calls.CallTarget0 function" (see here).

Zbychs

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this