next up previous contents
Next: Result-variables Up: GdfidLs command language Previous: if elseif else endif   Contents

Macros

Anywhere in your inputfile you can define macros. A macro is enclosed between two lines: The first line contains the keyword macro followed by the name of the macro. All lines until a line with only the keyword endmacro are considered the body of the macro. When gd1 or gd1.pp find such a macro, they read it and store the body of the macro in an internal buffer.
Example
   #
   # This defines a macro with name 'foo'
   #
   macro foo
      echo I am foo, my first argument is @arg1
      echo The total number of arguments supplied is @nargs
   endmacro
When gd1 or gd1.pp find a call of the macro, the number of the supplied arguments is assigned to the variable @nargs, and the variables @arg1, @arg2, .. are assigned the values of the supplied parameters of the call. Similiar to the user definable variables (via sdefine), the values of the arguments are strings. Of course it is possible to have a string eg. '1e-4' which happens to be interpreted in the right context as a real number.
Example
   #
   # this calls 'foo' with the arguments 'hi', 'there'
   #
   call foo(hi, there)
Macro calls may be nested. The body of a macro may call another macro.