[IronPython] Latest Hosting API - question on evaluating expr/statements

Douglas Blank dblank at brynmawr.edu
Fri Oct 31 17:50:57 CET 2008


----- Curt Hagenlocher <curt at hagenlocher.org> wrote:
> The API documentation itself can be found at
> http://compilerlab.members.winisp.net/dlr-spec-hosting.pdf (PDF) or
> http://compilerlab.members.winisp.net/dlr-spec-hosting.doc (Word).  An
> update was just pushed yesterday.

Excellent! Thanks much for this.

I've taken a look at the updated text, and have a question about evaluating arbitrary user text. I'm allowing the user to evaluate an arbitrary expression OR a sequence of statements. If I use:

 source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
 object result = source.Execute(scope);

then it works for statements (with a null result). If I use:

 source = engine.CreateScriptSourceFromString(code, SourceCodeKind.InteractiveCode);
 object result = source.Execute(scope);

then that works fine with REPL expressions. As there isn't a Kind for either, would there be issues if I do:

try {
   source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
} catch (Exception e1) {
   try {
      source = engine.CreateScriptSourceFromString(code, SourceCodeKind.InteractiveCode);
   } catch (Exception e2) {
      // report error
   }
}

or is there a better way?

Thanks!

-Doug

> On Fri, Oct 31, 2008 at 8:45 AM, Douglas Blank <dblank at brynmawr.edu> wrote:
> 
> > What sources do you recommended for the latest IronPython RC1 hosting API?
> > As far as I have found most docs still use older API's and I don't think
> > Foord and Muirhead's latest available MEAP e-version is out yet. Thanks!
> >
> > -Doug
> > _______________________________________________
> > 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