Programmer Guide/Command Reference/DISPATCH: Difference between revisions
No edit summary |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
DISPATCH <var>function argList</var> [/Call] [/Silent] [/Prefix=X] [/To=Y] [/Fail=Z] | The <code>DISPATCH</code> command, well, dispatches a call to a class, i.e. a call where a class is being called like a macro. In this case, the <code>DISPATCH</code> command regards the first argument supplied to the class call as a function to invoke (see below), and the remaining arguments as arguments to these functions. | ||
DISPATCH <var>function argList</var> [ /Call ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /Prefix=<var>X</var> ] [ /To=<var>Y</var> ] [ /Fail=<var>Z</var> ] | |||
DISPATCH <var>function argList</var> [/Call] [/Silent] [/Prefix=X] [/To=Y] [/Fail=Z] | DISPATCH <var>function argList</var> [ /Call ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /Prefix=<var>X</var> ] [ /To=<var>Y</var> ] [ /Fail=<var>Z</var> ] | ||
'''/Read''' [ /Var=<var>A</var> /Delim=<var>C</var> /Args=<var>D</var> ] | |||
By default, the function to be invoked is a label whose name is built up from the static prefix <code>Cmd</code> and the first argument supplied to the class call. If, for example, there is a class called <code>Example</code>, and you invoke it with the statement <code>Example test one two three</code>, the DISPATCH command will jump to the label called <code>Cmdtest</code>, supplying it with the arguments <code>one</code>, <code>two</code>, and <code>three</code>, respectively. | |||
Additionally, the <code>DISPATCH</code> command will store the command (less the prefix "<code>cmd</code>") in the local variable <code>#cmd</code>. The command argument itself will be removed from the argument list. So the label the <code>DISPATCH</code> command jumps to will only see any further arguments, not the command itself. | |||
By default, the <code>DISPATCH</code> command will parse the arguments supplied to the class in the <code>[[Programmer Guide/Command Reference/ARG|ARG]]</code> style. If you prefer <code>[[Programmer Guide/Command Reference/READ|READ]]</code> style, you may ask for it by supplying the <code>/Read</code> option. In this case, you may also choose a delimiter character and several other options (see below). | |||
By default, the <code>DISPATCH</code> command will parse the arguments supplied to the class in the <code>[[Programmer Guide/Command Reference/ARG|ARG]]</code> style. If you prefer <code>READ</code> style, you may ask for it by supplying the | |||
You may influence all these parameters by either supplying arguments or options to the <code>DISPATCH</code> commands. There are the following options: | You may influence all these parameters by either supplying arguments or options to the <code>DISPATCH</code> commands. There are the following options: | ||
== Options == | |||
;<var>[[Programmer_Guide/Command_Reference_Options/Silent|/Silent]]</var> | |||
:If the command fails, it reports a warning instead of an error. | :If the command fails, it reports a warning instead of an error. | ||
;<var>/Prefix=X</var> | ;<var>/Prefix=X</var> | ||
:Use <code>X</code> instead of the default label prefix "<code>cmd</code>". | :Use <code>X</code> instead of the default label prefix "<code>cmd</code>". | ||
;<var>/To=Y</var> | ;<var>/To=Y</var> | ||
:Store the command word (less the prefix) in a variable called <code>Y</code> instead of "<code>#cmd</code>". | :Store the command word (less the prefix) in a variable called <code>Y</code> instead of "<code>#cmd</code>". | ||
;<var>/Fail=Z</var> | ;<var>/Fail=Z</var> | ||
:If there is no appropriate label to jump to, the command will jump to label <code>Z</code>. If you don't supply the "/Fail=" option, trying to jump to a non-existent label will lead to a run-time error. | :If there is no appropriate label to jump to, the command will jump to label <code>Z</code>. If you don't supply the "/Fail=" option, trying to jump to a non-existent label will lead to a run-time error. | ||
;<var>/Read</var> | ;<var>/Read</var> | ||
:Use this option if your class is being supplied with READ-style instead of [[Programmer Guide/Command Reference/ARG|ARG]]-style options (the latter is the default). | |||
: | ;<var>/Call</var> | ||
:Normally, the <code>DISPATCH</code> command will simply jump to the respective label. Now, if you supply the <code>/Call</code> option, instead of jumping (the [[Programmer_Guide/Command_Reference/GOTO|GOTO]] way), the command will <em>call</em> the respective label (the [[Programmer_Guide/Command_Reference/GOSUB|GOSUB]] way). In this case, as soon as the control flow reaches an appropriate <code>[[Programmer_Guide/Command_Reference/EXIT|EXIT]]</code> statement, it will resume with the statement following the <code>DISPATCH /Call</code> command. | |||
== Additional <code>READ</code>-style Options == | |||
When using <code>READ</code>-style parsing, i.e. when supplying the "/Read" option, there are the following additional options: | When using <code>READ</code>-style parsing, i.e. when supplying the "/Read" option, there are the following additional options: | ||
Line 48: | Line 49: | ||
:If you supply this option, the command will store the arguments (less the command argument!) to the variable <code>D</code>. | :If you supply this option, the command will store the arguments (less the command argument!) to the variable <code>D</code>. | ||
See the script <code>dispatch_example.sts</code> for an example of usage. | See the script <code>dispatch_example.sts</code> for an example of usage. |
Latest revision as of 17:12, 23 March 2011
The DISPATCH
command, well, dispatches a call to a class, i.e. a call where a class is being called like a macro. In this case, the DISPATCH
command regards the first argument supplied to the class call as a function to invoke (see below), and the remaining arguments as arguments to these functions.
DISPATCH function argList [ /Call ] [ /Silent ] [ /Prefix=X ] [ /To=Y ] [ /Fail=Z ]
DISPATCH function argList [ /Call ] [ /Silent ] [ /Prefix=X ] [ /To=Y ] [ /Fail=Z ] /Read [ /Var=A /Delim=C /Args=D ]
By default, the function to be invoked is a label whose name is built up from the static prefix Cmd
and the first argument supplied to the class call. If, for example, there is a class called Example
, and you invoke it with the statement Example test one two three
, the DISPATCH command will jump to the label called Cmdtest
, supplying it with the arguments one
, two
, and three
, respectively.
Additionally, the DISPATCH
command will store the command (less the prefix "cmd
") in the local variable #cmd
. The command argument itself will be removed from the argument list. So the label the DISPATCH
command jumps to will only see any further arguments, not the command itself.
By default, the DISPATCH
command will parse the arguments supplied to the class in the ARG
style. If you prefer READ
style, you may ask for it by supplying the /Read
option. In this case, you may also choose a delimiter character and several other options (see below).
You may influence all these parameters by either supplying arguments or options to the DISPATCH
commands. There are the following options:
Options
- /Silent
- If the command fails, it reports a warning instead of an error.
- /Prefix=X
- Use
X
instead of the default label prefix "cmd
".
- /To=Y
- Store the command word (less the prefix) in a variable called
Y
instead of "#cmd
".
- /Fail=Z
- If there is no appropriate label to jump to, the command will jump to label
Z
. If you don't supply the "/Fail=" option, trying to jump to a non-existent label will lead to a run-time error.
- /Read
- Use this option if your class is being supplied with READ-style instead of ARG-style options (the latter is the default).
- /Call
- Normally, the
DISPATCH
command will simply jump to the respective label. Now, if you supply the/Call
option, instead of jumping (the GOTO way), the command will call the respective label (the GOSUB way). In this case, as soon as the control flow reaches an appropriateEXIT
statement, it will resume with the statement following theDISPATCH /Call
command.
Additional READ
-style Options
When using READ
-style parsing, i.e. when supplying the "/Read" option, there are the following additional options:
- /Var=A
- If you supply this option, the command will read from a variable called
A
. By default, it will read from#argv
, i.e. from the argument list supplied to the called class.
- /Delim=C
- If supplied, the command will parse arguments separated by the delimiter character
C
(which actually must be a character). This is equivalent to the delimiter character supplied to theREAD
family of commands (see there).
- /Args=D
- If you supply this option, the command will store the arguments (less the command argument!) to the variable
D
.
See the script dispatch_example.sts
for an example of usage.