Posted by
dscho on
Mar 20, 2013; 4:39pm
URL: http://imagej.273.s1.nabble.com/isOpen-path-tp5002210p5002316.html
Dear Wayne,
On Mon, 18 Mar 2013, Rasband, Wayne (NIH/NIMH) [E] wrote:
> On Mar 17, 2013, at 11:00 AM, Johannes Schindelin wrote:
>
> > The trick is not to use a 'return' statement (because -- as you
> > pointed out correctly -- the top-level script is not a function), but
> > an unassigned expression:
> >
> > eval("script", "1;");
> >
> > This patch (which you can conveniently get into your working directory
> > by calling "git pull git://github.com/dscho/imagej1 fix-js-return")
> > makes that work:
>
> It does work and it is in today's ImageJ 1.47n daily build. Thanks for
> providing this solution.
You're welcome. Although I'd like to mention that it would have been
easier to simply pull than to reapply things by hand.
> >> Passing of arguments to JavaScript scripts also needs to be fixed.
> >> How would you propose doing that?
> >
> > I do not think that there is a lot to fix. Last time I tried (with
> > Fiji's scripting framework, which I would have been happy to
> > contribute to ImageJ 1.x), using GenericDialog instances (and calling
> > the scripts via run(..., args);) worked just fine.
>
> Sorry, I should have been more specific. I am trying to figure out how
> this method
>
> public String runJavaScript(String script, String arg)
>
> in the Macro_Runner class should pass the string argument to the script.
> The only thing I can think of is to append a line of code something like
>
> arg = "value of 'arg'";
>
> to the script before it is evaluated. The script could then retrieve the
> argument by accessing the 'arg' variable. That would work but it doesn't
> seem like a very elegant solution.
Well, when you call the script, you can prepend it with anything anyway.
However, if you use the Java scripting API (as we already do in ImageJ2's
scripting framework -- hence my offer to help you avoid reinventing the
wheel with ImageJ 1.x), you can call ScriptEngine#put(String, Object) to
set local variables:
http://docs.oracle.com/javase/6/docs/api/javax/script/ScriptEngine.html#put%28java.lang.String,%20java.lang.Object%29I can easily make a pull'able branch to implement that, but I have the
impression that you want to implement it yourself anyway. If you would
like me to provide an easy-to-integrate change, however, please just let
me know! I'll be more than happy to contribute it!
Ciao,
Johannes
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html