[IronPython] Need a Good Embedded Example
Michael Foord
fuzzyman at voidspace.org.uk
Thu Oct 18 03:59:39 PDT 2007
Hello Joshua,
I'll take a look at this.
It is really easy for IronPython 1 and everything has changed for IP 2
(and the docs are not exactly complete).
It just takes a bit of exploration. You need to be able to set some
globals in the default module (where you can make your .NET objects
available to IP code - and then pull the globals back out after
executing the Python).
Michael
http://www.manning.com/foord
Joshua J. Pearce wrote:
> OK, please forgive my earlier vagueness. What I want to do is as follows:
>
> 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?
>
> Thanks,
>
> -Josh Pearce
>
>
>
>
> On 10/17/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:
> > I am looking for an embedded IronPython 2.0 example beyond the
> simple hello
> > world one I quoted before.
> >
> > What I want to know is:
> >
> > 1) How to get variable output from the script back to my c# code.
>
> I have a quick section in this article...
> http://www.codeproject.com/useritems/pswrdgeniron.asp
>
> You can view the source here...
> http://pswrdgen.googlecode.com/svn/trunk/pswrdgeniron/pswrdgeniron/Form1.cs
> <http://pswrdgen.googlecode.com/svn/trunk/pswrdgeniron/pswrdgeniron/Form1.cs>
>
> Microsoft.Scripting.ScriptDomainManager.CurrentManager.Host.DefaultModule.SetVariable
>
> > 2) How to call scripts with multiple statements.
>
> multiple statements? Do you mean call the methods in an imported
> script?
>
> > 3) Do all variables need to be set on the script object, or can
> their
> > declaration just be part of the script code?
>
> It depends what you are doing and how your app is designed.
>
> > 4) Is there a good and simple example anywhere that shows how to
> host the
> > IronPython engine in a c# app and let users manipulate your
> program objects
> > via ipy scripts?
>
> My article above.
>
> > 5) How can I expose c# methods to as IPY functions?
>
> Not sure I understand your question here. Can't you have a c# method
> then do something like pe.Execute("my py code here")?
> --
> Later, JoeSox
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
>
> --
> Joshua Pearce
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
More information about the Users
mailing list