<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> {The S-lang C Library Reference}: SLadd_intrinsic_function</TITLE>
<LINK HREF="cref-102.html" REL=next>
<LINK HREF="cref-100.html" REL=previous>
<LINK HREF="cref.html#toc101" REL=contents>
</HEAD>
<BODY>
<A HREF="cref-102.html">Next</A>
<A HREF="cref-100.html">Previous</A>
<A HREF="cref.html#toc101">Contents</A>
<HR>
<H2><A NAME="SLadd_intrinsic_function"></A> <A NAME="s101">101. <B>SLadd_intrinsic_function</B></A></H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Add a new intrinsic function to the interpreter
<DT><B> Usage </B><DD><P><CODE>int SLadd_intrinsic_function (name, f, type, nargs, ...)</CODE>
<BLOCKQUOTE><CODE>
<PRE>
    char *name
    FVOID_STAR f
    unsigned char type
    unsigned int nargs
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Description </B><DD><P>The <CODE>SLadd_intrinsic_function</CODE> function may be used to add a new
intrinsic function.  The <B>S-lang</B> name of the function is specified by
<CODE>name</CODE> and the actual function pointer is given by <CODE>f</CODE>, cast
to <CODE>FVOID_STAR</CODE>.  The third parameter, <CODE>type</CODE> specifies the
return type of the function and must be one of the following values:
<BLOCKQUOTE><CODE>
<PRE>
    SLANG_VOID_TYPE   (returns nothing)
    SLANG_INT_TYPE    (returns int)
    SLANG_DOUBLE_TYPE (returns double)
    SLANG_STRING_TYPE (returns char *)
</PRE>
</CODE></BLOCKQUOTE>

The <CODE>nargs</CODE> parameter specifies the number of parameters to pass
to the function.  The variable argument list following <CODE>nargs</CODE>
must consists of <CODE>nargs</CODE> integers which specify the data type of
each argument.
<P>The function returns zero upon success or <CODE>-1</CODE> upon failure.
<DT><B> Example </B><DD><P>The <B>jed</B> editor uses this function to change the <CODE>system</CODE>
intrinsic function to the following:
<BLOCKQUOTE><CODE>
<PRE>
     static int jed_system (char *cmd)
     {
        if (Jed_Secure_Mode)
          {
            msg_error ("Access denied.");
            return -1;
          }       
        return SLsystem (cmd);
     }
</PRE>
</CODE></BLOCKQUOTE>

After initializing the interpreter with <CODE>SLang_init_slang</CODE>,
<B>jed</B> calls <CODE>SLadd_intrinsic_function</CODE> to substitute the above
definition for the default <B>S-lang</B> definition:
<BLOCKQUOTE><CODE>
<PRE>
     if (-1 == SLadd_intrinsic_function ("system", (FVOID_STAR)jed_system,
                                          SLANG_INT_TYPE, 1,
                                          SLANG_STRING_TYPE))
       return -1;
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>SLadd_intrinsic_variable, SLadd_intrinsic_array</CODE>
</DL>
<P>
<P>
<HR>
<A HREF="cref-102.html">Next</A>
<A HREF="cref-100.html">Previous</A>
<A HREF="cref.html#toc101">Contents</A>
</BODY>
</HTML>
