(Created page with "The '''$*''' identifier left the help file a while ago, after while loop were introduced, it's now an undocumented identifier. $* is extremely powerful because is it much fas...") |
|||
Line 1: | Line 1: | ||
− | The '''$*''' | + | The '''$*''' allows you to iterates over all the token contained in $1-, like a while loop, $* left the help file a while ago, after while loops were introduced, it's now an undocumented identifier. |
$* is extremely powerful because is it much faster than using a while loop on a list of token, consider the following: | $* is extremely powerful because is it much faster than using a while loop on a list of token, consider the following: | ||
Line 11: | Line 11: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
this can be written as | this can be written as | ||
+ | <syntaxhighlight lang="mIRC"> | ||
+ | tokenize 32 a b c d | echo -a $* | ||
+ | </syntaxhighlight> | ||
+ | And it's faster, cool isn't it? | ||
+ | |||
+ | == Notes & quirks == | ||
+ | |||
+ | Why was the $* identifiers removed from the help file? Well because it doesn't really work the same way the others identifiers does, and because it's quirky: | ||
+ | |||
+ | mIRC takes the command $* appears in and replace all of its occurences in the line by a special marker: `~$*: you can see that by doing for example: | ||
+ | |||
+ | //tokenize 32 abcd | echo -a $left($*,1) $+ $chr(3) $+ $mid($*,2) | ||
+ | |||
+ | Let's take a look at this: //tokenize 32 abcd | echo -a $mid($*,2) | ||
+ | |||
+ | Why isn't this returning bcd? That's because of the usage of the special marker `~$*, mIRC store that the command is "echo -a $mid(`~$*,2)". | ||
+ | |||
+ | Then for each token, (here only $1 == abcd), evaluate the line first, here $mid(`~$*,2) is ~$*, and then mIRC replaces the marker by the token and execute the echo command, however after an operation like $mid here, that marker can't be found, you basically cannot get the correct value of $* inside an identifier. | ||
+ | |||
+ | There is a workaround to that issue though, with scid and scon: | ||
+ | <syntaxhighlight lang="mIRC"> | ||
+ | //tokenize 32 abcd | scon -r echo -a $!mid( $* ,2) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Here mIRC replace $* by the marker, but scon has an extra evaluation system which fits perfectly here, $* mechanism is enabled on scon, mIRC store the command of the $* as "scon -r echo -a $!mid( `~$* ,2)" | ||
+ | |||
+ | Then for each token, mIRC evaluates the line, which becomes: "scon -r echo -a $mid( abcd ,2)" and then finally the scon command is executed, resulting in the expected value echoed. | ||
+ | |||
+ | Another issue is that you cannot call $* more than once in the same scope the command will simply be skipped, however... this can be worked around :) | ||
+ | |||
+ | If you retokenize after using $*, forcing the update of $1-, you can use $* again but only if the number of tokens you pass is higher than the previous number of token you passed, and $* will only start from that previous number of token + 1: | ||
+ | <syntaxhighlight lang="mIRC"> | ||
+ | //tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | As you can see with this line, the second tokenize's first 3 token "4 5 6" are dumb tokens passed to fill in the gap, you can use $1- in front of your next tokenize command to start from those new tokens, like a normal situation. |
Revision as of 17:41, 3 September 2015
The $* allows you to iterates over all the token contained in $1-, like a while loop, $* left the help file a while ago, after while loops were introduced, it's now an undocumented identifier.
$* is extremely powerful because is it much faster than using a while loop on a list of token, consider the following:
var %list a b c d,%a 1 while ($gettok(%list,%a,32)) { echo -a $v1 inc %a }
this can be written as
tokenize 32 a b c d | echo -a $*
And it's faster, cool isn't it?
Notes & quirks
Why was the $* identifiers removed from the help file? Well because it doesn't really work the same way the others identifiers does, and because it's quirky:
mIRC takes the command $* appears in and replace all of its occurences in the line by a special marker: `~$*: you can see that by doing for example:
//tokenize 32 abcd | echo -a $left($*,1) $+ $chr(3) $+ $mid($*,2)
Let's take a look at this: //tokenize 32 abcd | echo -a $mid($*,2)
Why isn't this returning bcd? That's because of the usage of the special marker `~$*, mIRC store that the command is "echo -a $mid(`~$*,2)".
Then for each token, (here only $1 == abcd), evaluate the line first, here $mid(`~$*,2) is ~$*, and then mIRC replaces the marker by the token and execute the echo command, however after an operation like $mid here, that marker can't be found, you basically cannot get the correct value of $* inside an identifier.
There is a workaround to that issue though, with scid and scon:
//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)
Here mIRC replace $* by the marker, but scon has an extra evaluation system which fits perfectly here, $* mechanism is enabled on scon, mIRC store the command of the $* as "scon -r echo -a $!mid( `~$* ,2)"
Then for each token, mIRC evaluates the line, which becomes: "scon -r echo -a $mid( abcd ,2)" and then finally the scon command is executed, resulting in the expected value echoed.
Another issue is that you cannot call $* more than once in the same scope the command will simply be skipped, however... this can be worked around :)
If you retokenize after using $*, forcing the update of $1-, you can use $* again but only if the number of tokens you pass is higher than the previous number of token you passed, and $* will only start from that previous number of token + 1:
//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here
As you can see with this line, the second tokenize's first 3 token "4 5 6" are dumb tokens passed to fill in the gap, you can use $1- in front of your next tokenize command to start from those new tokens, like a normal situation.