[IronPython] Need a Good Embedded Example
fuzzyman at voidspace.org.uk
Thu Oct 18 19:04:25 CEST 2007
Joshua J. Pearce wrote:
> Thank you very much! Now, what if I the getcount() method was actually
> getcount(string arg1), is there a way to call it from within the IP
> script? Or do I need to parse the IP script ahead of time, and call
> the function myself? That would be like writing my own scripting
> language, so I hope there is a way to call the method from within IP
You should be able to place objects into the 'user scope' using the
same SetVariable technique. That way the user can call methods on these
objects from their code.
SomeObject is then available to user code as SomeName...
> Many thanks!
> - Josh Pearce
> On 10/18/07, *JoeSox* <joesox at gmail.com <mailto:joesox at gmail.com>> wrote:
> On 10/17/07, Joshua J. Pearce <joshua.pearce at gmail.com
> <mailto:joshua.pearce at gmail.com>> wrote:
> > OK, please forgive my earlier vagueness. What I want to do is as
> > pe = PythonEngine.CurrentEngine ;
> > //create a instance of my applications business logic layer class
> > myAppService = new AppService(_token);
> > //I want to be able to somehow make methods from the
> myAppService class
> > available to be called from Iron Python code.
> > //I know I could import the AppService dll and create my own
> instance in the
> > IP engine, but that's way too much overhead.
> > //How can I say: "Hey, pe, here is a method on my object,
> myAppService, that
> > I want you to make available when you execute a command?
> What are the return values of myAppService.ServiceMethod()?
> Depending upon these values, you will need to handle them before
> sending them to the pe.
> So it sounds like you need something like:
> public int COUNT;
> private void MyIPGetCount()
> //Call your Service method and assign return value to a global
> COUNT = myAppService.getcount ();
> //Create variable bridge from C# to IronPython engine
> //I like to pretend I am just using a IP command line to help
> figure out what I need to do
> pe.ExecuteCommand("PyCount = 0");
> //Set the IronPython bridge variables...
> pe.ExecuteCommand("PyCountTwo = PyCount");
> This is a simplified version of what I am guess what you need to do
> but there you go.
> Later, JoeSox
> Users mailing list
> Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
> Joshua Pearce
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users