[IronPython] IP 2 Hosting

Michael Foord fuzzyman at voidspace.org.uk
Sat Mar 29 18:32:15 CET 2008


Curt Hagenlocher wrote:
> Some of those look like names from A9, which have changed in B1.
I'm using B1. I expect they'll change in the next release though. *sigh* ;-)

In the old days a beta used to mean the API was fixed and it was only 
bugfixes that would go in... <0.5 wink>

Michael


>  
> The easiest way to evaluate an expression from scratch seems to be as 
> follows:
>  
>     ScriptEngine engine = ScriptRuntime.Create().GetEngine("py");
>     ScriptScope scope = engine.CreateScope();
>     ScriptSource source = engine.CreateScriptSourceFromString("1 + 1", 
> SourceCodeKind.Expression);
>     int result = source.Execute<int>(scope);
>
> On Sat, Mar 29, 2008 at 10:00 AM, Michael Foord 
> <fuzzyman at voidspace.org.uk <mailto:fuzzyman at voidspace.org.uk>> wrote:
>
>     Hello guys,
>
>     I'm trying to do some simple examples of hosting with IronPython
>     2. Boy
>     you made things more complicated than IronPython 1. :-)
>
>     Unfortunately the DLR hosting spec document is out of date. I have a
>     couple of questions (but will keep exploring).
>
>     The simplest use case is just to evaluate an expression and return
>     a result.
>
>     The hosting spec document mention 'ScriptRuntime.Execute(text)'. This
>     may or may not be the right way to evaluate an expression, but in any
>     case it has been removed.
>
>     An alternative is:
>
>        engine = PythonEngine.CurrentEngine # a ScriptEngine
>        unit = engine.CreateSourceUnitFromString(code, id)
>        result = unit.Execute()
>
>     Which is straightforward enough, however I can't see a way to set
>     TrueDivision using this technique.  (What is the 'id' by the way?)
>
>     I can see that TrueDivision is a setting on
>     IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule.
>     Can I set this on the engine somehow?
>
>     All the alternative seem to lead down a rabbit warren of 'create this
>     object - which requires this object - which you construct from another
>     object - which...'. I don't know which path to follow down the rabbit
>     hole...
>
>     :-)
>
>     Any suggestions to save me from madness?
>
>     Michael
>     _______________________________________________
>     Users mailing list
>     Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list