1
<doctitle>Scripting language syntax : aliases</doctitle>
5
<docsubtitle>Aliases</docsubtitle>
8
KVIrc supports definition of sub-procedures : aliases<br>
9
You can define an alias by using the built-in editor or by using the
10
<a href="alias.kvihelp">alias</a> command.<br>
13
<a href="alias.kvihelp">alias</a> saytoconsole { <a href="echo.kvihelp">echo</a> -w=<a href="s_console.kvihelp">$console</a> $1-; }
16
In the above example we define the command "saytoconsole"
17
that "echoes" the text passes as parameters to the console window.<br>
18
Now we can call it in the following way:<br>
21
saytoconsole This text will go to the console window
24
Inside the alias there are few special identifiers:<br>
25
$0 : evaluates to the name of the alias<br>
26
$1 : evaluates to the first positional parameter<br>
27
$2...$9999999 : same as above but for the second, third.....parameter<br>
28
$# : evaluates to the number of the parameters passed.<br>
29
$1- : evaluates to all the positional parameters<br>
30
$2- : evaluates to all the positional parameters starting at the second one.<br>
31
$1-2 : evaluates to the parameters 1 and 2
32
$3-12 : evaluates to the parameters from 3 to 12
37
<docsubtitle>User definable functions</docsubtitle>
40
KVIrc does not provide a direct way to create user definable functions.<br>
41
The function mechanism is emulated by aliases , the "bracket identifier" ${ }
42
and the <a href="setreturn.kvihelp">setreturn</a> command.<br>
45
<a href="alias.kvihelp">alias</a> sumthreenumbers <a href="setreturn.kvihelp">setreturn</a> <a href="s_calc.kvihelp">$calc</a>( $1 + $2 + $3)
46
<a href="echo.kvihelp">echo</a> ${ sumthreenumbers 10 20 30; }
49
The example above will print 60 in the current window.<br>
50
<a href="setreturn.kvihelp">setreturn</a> sets the return value of the alias
51
to the sum of the three numbers.<br>
52
The "${ }" identifier braces execute the command specified inside and evaluate
53
to the return value of that command.<br>
54
You can execute more commands in the identifier braces
55
and <a href="setreturn.kvihelp">setreturn</a> may be not called or called more than once.<br>
56
Obviously the last call defines the effective value returned by ${ }.<br>
57
Some other KVIrc commands set the return value.<br>
58
All the alias calls set the return value
59
to the return value of the internal sequence of commands
60
(<a href="alias.kvihelp">alias</a> propagates the return value).<br>
63
<a href="alias.kvihelp">alias</a> propagate sumthreenumbers 15 5 20
64
<a href="echo.kvihelp">echo</a> ${ propagate }
67
In the example above "sumthreenumbers" sets the return value of the
68
"propagate" alias.<br>
69
The <a href="parse.kvihelp">parse</a> command also propagates the
71
<a href="op.kvihelp">op</a> , <a href="deop.kvihelp">deop</a> ,
72
<a href="ban.kvihelp">ban</a> and other similar commands
73
return the number of messages effectively sent to the server.<br>
77
<a href="alias.kvihelp">alias</a> test <a href="setreturn.kvihelp">setreturn</a> 10; op Pragma; echo Opped Pragma;
78
<a href="echo.kvihelp">echo</a> ${ test }
81
In the example above the <a href="setreturn.kvihelp">setreturn</a> command is
82
useless: <a href="op.kvihelp">op</a> resets the return value to 1 that is the number
83
of MODE +o messages sent.<br>
84
<a href="echo.kvihelp">echo</a> does not modify the return value.<br>
87
In the help page of each command you will find the information
88
about the return value.<br>
89
Seem complicated ? :)<br>
94
<a href="index.kvihelp">Main index</a> , <a href="syntax.kvihelp">Syntax index</a>