[IronPython] IP 2 Hosting
curt at hagenlocher.org
Sat Mar 29 18:23:43 CET 2008
Some of those look like names from A9, which have changed in B1.
The easiest way to evaluate an expression from scratch seems to be as
ScriptEngine engine = ScriptRuntime.Create().GetEngine("py");
ScriptScope scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString("1 + 1",
int result = source.Execute<int>(scope);
On Sat, Mar 29, 2008 at 10:00 AM, Michael Foord <fuzzyman at voidspace.org.uk>
> 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
> 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
> Any suggestions to save me from madness?
> Users mailing list
> Users at lists.ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users