Login  Register

Re: isOpen("path") ?

Posted by dscho on Mar 21, 2013; 9:25pm
URL: http://imagej.273.s1.nabble.com/isOpen-path-tp5002210p5002341.html

Hi Wayne,

On Thu, 21 Mar 2013, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Mar 20, 2013, at 1:45 PM, Johannes Schindelin wrote:
>
> > On Wed, 20 Mar 2013, Johannes Schindelin wrote:
> >
> >> http://docs.oracle.com/javase/6/docs/api/javax/script/ScriptEngine.html#put%28java.lang.String,%20java.lang.Object%29
> >>
> >> I 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!
> >
> > I made the change, tested it, and you can easily pull it like this:
> >
> > git pull git://github.com/dscho/imagej1 javascript-arg
>
> I decided to prepend a getArgument() function to the script in order to
> be consistent with the way arguments are passed to macros. This make it
> easier to document how the Macro_Runner.runMacroFile() method works:
>
>    /** Opens and runs the specified macro or script file on the current
>         thread. The file is assumed to be in the ImageJ/macros folder
>         unless 'name' is a full path. ".txt"  is added if 'name' does not
>         have an extension. The macro or script can use the getArgument()
>         function to retrieve the string argument.
>    */
>    public String runMacroFile(String name, String arg) {

Nice! It is even thread-safe (in contrast to the macro function, but then,
too many things in macros are thread-unsafe already to allow for
concurrent execution). At least if ScriptEngines are not reused (I vaguely
remember reading someething about this not being guaranteed, but in that
case, my put() approach would be thread-unsafe, too).

The only problem I see with the current getArgument approach is that it
does not adhere to Postel's law by leaving the arg unquoted.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html