From: Johann P. <joh...@ch...> - 2007-08-09 11:16:30
|
Hi, thanks for helping me here! Oti wrote: > Hi, > > from > https://scripting.dev.java.net/source/browse/scripting/engines/jython/src/com/sun/script/jython/JythonScriptEngine.java?rev=1.4&view=markup > you can see the following comment: > > /* > * Jython parser seems to have 3 input modes (called compile "kind") > * These are "single", "eval" and "exec". I don't clearly understand > * the difference. But, with "eval" and "exec" certain features are > * not working. For eg. with "eval" assignments are not working. > * I've used "exec". But, that is customizable by special attribute. > */ > > I suppose you could force 'eval' if you have a real expression, but I > never tried that. > I am not entirely sure how I would have to do this in my application. Given my current code (that is essentially identical for all scripting languages I have embedded in my application): ScriptEngineManager scriptEngineManager = new ScriptEngineManager(myOwnClassLoader); // this returns non-null: scriptEngine = scriptEngineManager.getEngineByName("jython"); // .... Object value = scriptEngine.eval(command); ... what would I have to add to force "eval" mode of the Jython parser for evaluating command? > What I have tried is to get instances back. See the > JyClass.forScript() / newInstance() here: > http://jython.extreme.st/talk/talk.html > The code for JyClass can be found here: > http://jython.extreme.st/downloads/downloads.html, I am afraid I do not really understand how this relates to scriptEngine.eval() I must admit that I essentially just followed boilerplate instructions of how to get scripting engines to work so far and it turned out that was successful with JRuby, Groovy, and JavaScript. My application essentially should allow the use of one of several scripting languages in a console and this is done by creating the apropriate scripting engine with getEngineByName and then using this in a GUI that simulates an interactive shell. All scripting languages are supposed to use scriptEngine and work in roughly the same way. So -- I am still not sure if it is possible to achive this with the Jython engine. I would have loved to support Jython for those who like the language (though I am not a P/Jython programmer myself), but if this cannot be done in roughly the same way as with JRuby, JavaScript, or Groovy, I guess I will just not include Jython for now. Thanks for your valuable feedback! Johann |