Macro Environment

From STX Wiki
Jump to navigation Jump to search

This STx-related article may be outdated.

The following variables are reserved in the macro environment.

#ARGC - the number of arguments

If a macro is defined with the extended header format (see Macros and Classes), the number of arguments passed is assigned to this variable (otherwise the number of arguments can be found in the variable #read after READVAR #argv has been called). Note that #argc only contains the correct number of arguments if they are blank separated.

#ARGV - the argument string

When a macro, subroutine or member function is called, the variable #ARGV contains the argument string passed by the calling command. The command READVAR or (for macros only) the extended header format can be used to separate the arguments.

If a macro passes its environment to another macro (MACROX) or a subroutine (GOSUBX) the variables #ARGV, #ARGC and #MAC in its environment are changed!

#MAC - the macroname|labelname|classname

The variable #MAC identifies the currently active macro macroname, the subroutine labelname or the member function classname.

#NEW - newitemname

If a NEW command creates a new item successfully, the name of the new item is assigned to the variable #NEW. To save the (e.g. automatically generated) name, it must be assigned to another variable before the next NEW command is executed.

#qarg You may use #qarg in order to pass ARG-style arguments to another function without getting them distorted in any way. This sounds stupid, but consider what happens when calling a user-defined function, e.g. HUGO, with the statement "HUGO $#argv": if the ARG-style arguments you got contain whitespace, the function HUGO will end up with a different argument list than expected (and than the caller has passed to your function).

If, on the other hand, you use the statement "HUGO $#qargv", the callee, HUGO, will get EXACTLY the same argument(s) as the function calling HUGO has been passed.

#qargc contains the number of ARG-style arguments passed to the current. See #qarg for details.

#READ - the number of assigned variables

The variable #READ is set to the number of assigned target-variables by any type of READ command.

#SHELL - the new shell id

When the command SHELL is used to start a new shell, the id of the started shell is stored in the variable #SHELL of the caller's environment (see also variable SHELL).

#THIS - the instance item name

When a member function is called, the variable #THIS is set to the name of the instance item.