[IronPython] Calling functions in IronPython that don't really exist

James Matthews nytrokiss at gmail.com
Thu Dec 4 22:17:23 CET 2008


You can just create the function name and do nothing with it. In Cpython i
would use meta classes but idk if they are in IronPython

On Thu, Dec 4, 2008 at 11:13 PM, Jeff Slutter <jslutter at reactorzero.com>wrote:

> I'm writing an application that I want to provide runtime scripting via
> IronPython for. This application loads "plug-ins" from assemblies to add
> functionality.
>
> Each plug-in is a class with, for the sake of simplicity, a "Do" function.
>
> What I'm trying to figure out is that if I have a class like:
>
> class AddNumbers
> {
>    public string Do( params object[] args )
>    {
>        ..check args..
>        ..add the two arguments..
>        ..return the result as a string..
>    }
> }
>
>
> That I could call it from IronPython like:
>
> AddNumbers( 3, 4 )
>
> When that happens a new instance of the AddNumbers class is created, the
> arguments are then passed to the Do member function, the result is
> returned back to Python.
>
> This may seem like a weird way for scripting. But, doing it this way I
> can do some other important things, such as keeping a history of the
> commands. If, along with Do, the commands have Undo and Redo functions,
> then I can keep the instances of the commands stored and should the user
> need to undo their command, I can internally run the Undo function.
>
> Any ideas on how I should approach this? I don't mind having to do a
> good chunk of backend work so that to add new command plugins, I just
> have to write a class with a Do function and possibly provide some
> Attributes if necessary. If I have to make some concessions that is
> fine, but I need to stick with the concept of creating an instance of a
> class and executing a function to perform the operation.
>
> I assume I'm either going to have to generate some sort of thunk
> function (I have no idea where to start) or provide some sort of
> 'command runner' that really gets called.
>
> Any help or guidance is mighty appreciated,
> Jeff
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



-- 
http://www.astorandblack.com/

http://www.thewatcherys.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081204/023dde94/attachment.html>


More information about the Ironpython-users mailing list