|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Fri Oct 08, 2004 4:48 pm
Tough #if statement |
Does anyone know how/why the script below works?
#CLASS {toughif}
#ALIAS test {#if %1 <@truebranch> <@falsebranch>}
#VAR truebranch {#echo "This branch is the:"
#echo "True Branch"}
#VAR falsebranch {#echo "This branch is the:"
#echo "False Branch"}
#CLASS 0
The syntax checker complains, but I decided I was skilled enough to ignore it . Is this syntax supported though or is it just luck that it works?
Edit: Test it with: "test 1" and "test 0" |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Fri Oct 08, 2004 10:23 pm |
First your #VAR assignments result in the variables containing "#echo This branch is the:;#ECHO Whichever Branch".
The %1 is subject to early expansion. It is limited to a single word or will contain its own delimeters. While it is best to put the () around the expression parameter the whole parameter is sent for evaluation.
The #IF takes 2 or 3 parameters. The <> classes as a delimeter (undocumented). So everything is technically seperated and correctly parsed as the desired parameters for #IF.
Finally the <@whicheverbranch> is passed whole to the parser. It now sees the <> as an expansion indicator and preforms unlimited expansion. This proccess strips the quotes of the variable and allows the parser to preform execution of the contained script.
The syntax itself "sloppy", it doesn't really fall into either a supported or unsupported category. I would personally call it unsupported since I think Zugg would never document any of those shortcuts. I know I wouldn't. In fact I have been removing most references to the <> expansion shortcut from the help, there weren't many to begin with. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
|
|