I'm integrating an IronPython scritping engine into my C# raytracer which, so far, has been a breeze even though I'm completely new to Python. There is one particular thing, though, that I need help with. I have a C# class which defines a constructor like this:
public CameraAnimation(Action<Camera, float> animation)
In C#, I would instantiate this like so:
var camAnimation = new CameraAnimation((camera, time) => camera.Position += new Vector(1, 0, 0));
I can't quite figure out how to make a similar assignment for the Action object in IronPython, so how would the Python syntax look?
Assuming I interpreted this right, and Action is a generic delegate, the below works (the stubs I used are included).
Python:
CSharp:
I corrected the above to use System.Action, and it no longer requires explicit reflection. It's a bit weird though. For some reason, I could construct a user-created delegate like:
but could not do so with System.Action. E.g. with
explicitSystemAction is null. TestAction was just defined as:
But luckily either way it's fine to just do:
or
though for some reason I don't remember that working when I first tried...