<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="newfun" xml:lang="en">
    <refnamediv>
        <refname>newfun</refname>
        <refpurpose>add a name in the table of functions</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>newfun(function_name, function_ptr)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>function_name</term>
                <listitem>
                    <para>a character string, giving a valid function name</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>function_ptr</term>
                <listitem>
                    <para>a positive number with integer value (see below)</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>Utility function (for experts only). </para>
        <para>
            Adds the name <literal>function_name</literal> in the table of
            functions known to the interpreter.
        </para>
        <para>
            <literal>function_ptr</literal> is an integer
            <literal>1000*fun+fin</literal> where <literal>fun</literal> and
            <literal>fin</literal> are the internal coding of the primitive
            <literal>function_name</literal>.
        </para>
        <para>This function may be useful to associate a primitive to a
            gateway called in <literal>"gw_user.c"</literal>
            (<literal>fun=14</literal>). Note however that the <link linkend="ilib_build">ilib_build</link> function is a more easy way
            to extend Scilab with new functions based on C, C++ or Fortran
            code.
        </para>
        <para>This function may also be used to add an alias or to rename
            to an existing primitive function.
        </para>
        <para>
            Used with <literal>funptr</literal> and <literal>clearfun</literal>
            one can add an alias or  rename an existing primitive function.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
     absptr=funptr("abs");// get the function_ptr associated with the abs function
     newfun("abs_bis",absptr) // create an alias of the abs function
     abs_bis(-1+%i)
     clearfun("abs") // remove abs as a known function

      //redefine abs
      function y=abs(x)
	y=abs_bis(real(x));
      endfunction

     abs(-1+%i)
  ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="clearfun">clearfun</link>
            </member>
            <member>
                <link linkend="funptr">funptr</link>
            </member>
            <member>
                <link linkend="ilib_build">ilib_build</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
