Scripting in StreamServe > Function files > User created script functions with arguments > Using local variable names as arguments to a function

Using local variable names as arguments to a function
You can declare arguments to a function as local variable names. Variables declared in the function declaration, or in the function body, are local to the scope of the function call. Compared to when all variables were global, there is no risk of overwriting global variables, thus making custom functions more portable.
Such a function declaration has the following form:
func name([type name,])
{
 [statements]
 [return value]
}
Example 36
func myfunc(str firstname, str lastname, num age)
{
if (age > 29)
 return firstname + lastname;
else
 return 0;
}
 
Using the #N syntax to read arguments
It is still possible to use the #N syntax to retrieve the arguments to a function even when you use variable names as arguments..
Example 37
#N syntax when arg variables are declared
{
log(1, echo("hello!"));
}
func echo(str string)
{
 return #1;
}
 
 
You can not initialize argument variables in the function declaration. This must be done in the function body.
 
 
OpenText StreamServe 5.6 Updated: 2013-03-01