Next Previous Contents

101. SLadd_intrinsic_function

Synopsis

Add a new intrinsic function to the interpreter

Usage

int SLadd_intrinsic_function (name, f, type, nargs, ...)

    char *name
    FVOID_STAR f
    unsigned char type
    unsigned int nargs
Description

The SLadd_intrinsic_function function may be used to add a new intrinsic function. The S-lang name of the function is specified by name and the actual function pointer is given by f, cast to FVOID_STAR. The third parameter, type specifies the return type of the function and must be one of the following values:

    SLANG_VOID_TYPE   (returns nothing)
    SLANG_INT_TYPE    (returns int)
    SLANG_DOUBLE_TYPE (returns double)
    SLANG_STRING_TYPE (returns char *)
The nargs parameter specifies the number of parameters to pass to the function. The variable argument list following nargs must consists of nargs integers which specify the data type of each argument.

The function returns zero upon success or -1 upon failure.

Example

The jed editor uses this function to change the system intrinsic function to the following:

     static int jed_system (char *cmd)
     {
        if (Jed_Secure_Mode)
          {
            msg_error ("Access denied.");
            return -1;
          }       
        return SLsystem (cmd);
     }
After initializing the interpreter with SLang_init_slang, jed calls SLadd_intrinsic_function to substitute the above definition for the default S-lang definition:
     if (-1 == SLadd_intrinsic_function ("system", (FVOID_STAR)jed_system,
                                          SLANG_INT_TYPE, 1,
                                          SLANG_STRING_TYPE))
       return -1;
See Also

SLadd_intrinsic_variable, SLadd_intrinsic_array


Next Previous Contents