Re: global var in macro

Posted by Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/Reslice-stack-at-various-angles-tp3694050p3694053.html

This bug is fixed in the ImageJ 1.42h daily build. Pressing ctrl-r
(Macros>Run Macro) in the macro editor now runs the first macro in a
macro set regardless of whether or not there are global variables. This
means you can now also debug the first macro in a macro set by pressing
ctrl-d (Debug>Debug Macro) and single step through the code by pressing
ctrl-e (Debug>Step). On the Mac you can debug any macro in a macro set
by running it from the Macros menu with the alt key down. This does not
work on Windows because of a Java bug.

-wayne


On Jan 15, 2009, at 3:05 PM, Wayne Rasband wrote:

> We are having a problem with using global variables in macros. A var
> declaration
> at the beginning of the macro file seems to cause everything to hang.
>
> For example, here is a small macro copied from a previous posting on
> the subject:
>
> //================
>
> var x;
>
> macro "test" {
>     x=10;
>     f();
>     print (x);
>     exit("Terminating normally...");
> }
>
> function f(){
>       x = 20;
> }
>
> //=================
>
> If I omit var x; declaration, then it runs fine (but of course it
> prints
> that x is 10, as expected).
>
> If I include the var x; declaration, then it hangs. I ran it with the
> debugger
> and single step. It advances past the var declaration and highlights
> the
> macro "test" { line. There it stops (ie, cntl-E will not advance
> operation to
> the next line).
>
> It seems something obvious that I missed. I did not find this problem
> in the
> archives.
>
> --aryeh
> --
> Aryeh Weiss
> School of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384050
>