• Advertisement
Sign in to follow this  

[XNA/IronPython] Invoking delegates from IronPython

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Thanks, I got it to work. I just added an easier interface to the InputManager through my script library. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement