Sophie

Sophie

distrib > Mandriva > 8.1 > i586 > by-pkgid > 700475c8ae73fb4d57b6df4485c29e1c > files > 143

slang-doc-1.4.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> {The S-lang C Library Reference}: SLexecute_function</TITLE>
 <LINK HREF="cref-86.html" REL=next>
 <LINK HREF="cref-84.html" REL=previous>
 <LINK HREF="cref.html#toc85" REL=contents>
</HEAD>
<BODY>
<A HREF="cref-86.html">Next</A>
<A HREF="cref-84.html">Previous</A>
<A HREF="cref.html#toc85">Contents</A>
<HR>
<H2><A NAME="SLexecute_function"></A> <A NAME="s85">85. <B>SLexecute_function</B></A></H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Execute a <B>S-lang</B> or intrinsic function
<DT><B> Usage </B><DD><P><CODE>int SLexecute_function (SLang_Name_Type *nt)</CODE>
<DT><B> Description </B><DD><P>The <CODE>SLexecute_function</CODE> allows an application to call the
<B>S-lang</B> function specified by the <CODE>SLang_Name_Type</CODE> pointer
<CODE>nt</CODE>.  This parameter must be non <CODE>NULL</CODE> and must have been
previously obtained by a call to <CODE>SLang_get_function</CODE>.
<DT><B> Example </B><DD><P>Consider the <B>S-lang</B> function:
<BLOCKQUOTE><CODE>
<PRE>
     define my_fun (x)
     {
        return x^2 - 2;
     }
</PRE>
</CODE></BLOCKQUOTE>

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 <CODE>SLang_execute_function</CODE> by passing
the string <CODE>"my_fun"</CODE>.  A better way that is much faster is to
use <CODE>SLexecute_function</CODE>:
<BLOCKQUOTE><CODE>
<PRE>
      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 &lt; 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 (&amp;y, NULL, NULL))
                return -1;
              
              sum += y;
           }
         return sum;
      }
</PRE>
</CODE></BLOCKQUOTE>

Although not necessary in this case, <CODE>SLang_start_arg_list</CODE> and
<CODE>SLang_end_arg_list</CODE> were used to provide the function with
information about the number of parameters passed to it.
<DT><B> See Also </B><DD><P><CODE>SLang_get_function, SLang_start_arg_list, SLang_end_arg_list</CODE>
</DL>
<P>
<P>
<P>
<HR>
<A HREF="cref-86.html">Next</A>
<A HREF="cref-84.html">Previous</A>
<A HREF="cref.html#toc85">Contents</A>
</BODY>
</HTML>