Hi Jim,
   Thank you very much for the response. I was looking for a Scala Engine, so I will definitely have to look at the IFCX engines. :)

As for the Jython specific thing, if I understand you correctly it sounds as if the engine functions this way due to the nature of the Python language itself, and to make it work how I want, some preprocessing of the scripts would be necessary.

Even when doing this, it sounds like some magic has to be done by assigning the last statement to some binding variable. Then I would need to retrieve the value of that binding variable.

Is this correct?

Thank you,

On Sat, Sep 27, 2008 at 9:39 PM, Jim White <jim@pagesmiths.com> wrote:
Hi Eric!

Yeah, I've had to deal with that myself with IFCX Wings.

The problem is that with Python/Jython statements do not have values. That means a script engine has to decide whether to evaluate statements or expressions, and if you just evaluate expressions there is very limited Python stuff you can do.

Sticking with statements brings another problem which is that the JSR-223 Jython engine from scripting.dev.java.net doesn't implement stdio properly.  There is a fixed version in IFCX SVN --- ah, wait, just checked and I see my fix has made it there!

The IFCX JSR-223 engines may still be of interest to those who want binaries that are built for JDK 1.5 and therefore work fine for both Java 5 and Java 6 users.


You'll also find Scala, OCaml, and Adenine there.


As for making Jython more embedded scripting friendly, that will entail doing some parsing tricks to decide whether you have an expression or some statements.  A plausible approach would be to examine the last line of the script and if it is an expression rather than a statement then code to make an assignment to a binding would be prepended.  You'll notice the Jython embedding examples use that style of code.


There is an expression evaluator in Jython, and you can call it instead of using JSR-223 (I also made a JSR-223 Jython engine that used it for testing but have not kept it around) for simple expressions.



Eric Berry wrote:

  I've created a jEdit plugin which uses the JSR-223 ScriptingEngine to execute Jython scripts. I have a question about the return values from Jython scripts.

If I have a script which consists of just "1 + 2", I'd expect to get a returned value of "3", but I always get null.

If I try to use a return, I get an exception about the return being in the wrong place.

Essentially, I want to be able to do this:
Object value = scriptEngine.eval("1 + 2");

and have value equal 3, I've test this out with a couple other ScriptEngines (Javascript, Groovy) and they behave this way.

Is there a way to get it the Jython ScriptEngine to act this way, and if not, is there a reason why?

Thank you for any help.

Learn from the past. Live in the present. Plan for the future.