Added in v2.0


Syntax: #VARF varname {value} classname

This command is used to create a user-defined function. VarName is the name of the function (do not include the @ at the start of the name), and value is an expression to assign to the function. You can use the parameters %1 to %99 to refer to arguments passed to your function.

NOTE: In TeSSH and in TeSSH versions prior to 2.0, this was the #FUNCTION command. In v2.0 or later, the #FUNCTION command creates script functions that require the #RETURN command, and #VARFUNC is used for inline user functions.

VARFUNC Examples

#VARFUNC fact {%if(%1<=1,1,%1*@fact(%eval(%1-1)))}
creates a user defined function to compute the factorial of a number. If the argument is less than or equal to one, one is returned, otherwise the argument is multiplied by the factorial of the argument minus one. Note that arguments to functions are normally just expanded and not evaluated, so we need the %eval function to force the subtraction of one.

#EVAL @fact(5)
will display 120 given the above definition

#SHOW @fact(5)

will display 5*4*3*2*1 given the above definition

Add comment

Login or register to post comments