Execute a S-lang or intrinsic function
int SLexecute_function (SLang_Name_Type *nt)
The SLexecute_function
allows an application to call the
S-lang function specified by the SLang_Name_Type
pointer
nt
. This parameter must be non NULL
and must have been
previously obtained by a call to SLang_get_function
.
Consider the S-lang function:
define my_fun (x)
{
return x^2 - 2;
}
Suppose that it is desired to call this function many times with
different values of x. There are at least two ways to do this.
The easiest way is to use SLang_execute_function
by passing
the string "my_fun"
. A better way that is much faster is to
use SLexecute_function
:
int sum_a_function (char *fname, double *result)
{
double sum, x, y;
SLang_Name_Type *nt;
if (NULL == (nt = SLang_get_function (fname)))
return -1;
sum = 0;
for (x = 0; x < 10.0; x += 0.1)
{
SLang_start_arg_list ();
if (-1 == SLang_push_double (x))
return -1;
SLang_end_arg_list ();
if (-1 == SLexecute_function (nt))
return -1;
if (-1 == SLang_pop_double (&y, NULL, NULL))
return -1;
sum += y;
}
return sum;
}
Although not necessary in this case, SLang_start_arg_list
and
SLang_end_arg_list
were used to provide the function with
information about the number of parameters passed to it.
SLang_get_function, SLang_start_arg_list, SLang_end_arg_list