C-API

Name

C-API --  C-functions that allows using C-language along with CLIP.

Function

double              _clip_parnd(ClipMachine * cm,int num)
int                 _clip_parni(ClipMachine * cm,int num)
long                _clip_parnl(ClipMachine * cm,int num)
void                _clip_retnd(ClipMachine * cm,double n)
void                _clip_retni(ClipMachine * cm,int n)
void                _clip_retnl(ClipMachine * cm,long n)

Description

CLIP's C-API is a set of C-functions that allows using C-language along with CLIP. It could be necessary for writing some speed critical functions of your project; for writing "wrappers" for existing 3rd party functions or whole libraries, etc. Besides, learning C-API will help you understand internal structure of CLIP.

C-functions aimed to be used with CLIP (that is, which can be called from some CLIP function, 'exported functions' in further) are in separate C source file(s). This file must include "clip.h", which contains declarations of C-API functions and structures.

Each exported function's name must have prefix 'clip_' and the name itself must be in capital letters. Type of function must be 'int' and it must get one and only parameter of type 'ClipMachine *', which is a pointer to the structure containing context of the current CLIP Virtual Machine.

Exported function should return 0 (zero) if successful, or appropriate error code (those described in error.ch, with 'EG_' prefix).

Example:
/* my.c */
#include <stdio.h>
#include "clip.h"

int clip_MYFUNCTION(ClipMachine *cm)
{
printf("Hello from MyFunction()\n");
return 0;
}
/* end of my.c */

/* test.prg */
MyFunction()
/* end of test.prg */

Compilation:

gcc -c -I${CLIPROOT}/include my.c
clip -eM test.prg my.o

Running:
#./test
Hello from MyFunction
#

Function _CLIP_PARND()

 _clip_parnd(ClipMachine * cm,int num) --> double

_clip_parnd() retrieves a numeric value passed as a parameter from CLIP and converts it to a double type.

Function _CLIP_PARNI()

 _clip_parni(ClipMachine * cm,int num) --> int

_clip_parni() retrieves a numeric value passed as a parameter from CLIP and converts it to an int type.

Function _CLIP_PARNL()

 _clip_parnl(ClipMachine * cm,int num) --> long

_clip_parnl() retrieves a numeric value passed as a parameter from CLIP and converts it to a long type.

Function _CLIP_RETND()

 _clip_retnd(ClipMachine * cm,double n) --> void

_clip_retnd() posts a numeric value into CLIP's return value area. When your exported function returns control to the calling CLIP program, the posted value becomes the CLIP return value of your exported function.

Function _CLIP_RETNI()

 _clip_retni(ClipMachine * cm,int n) --> void

_clip_retni() posts a numeric value into CLIP's return value area. When your exported function returns control to the calling CLIP program, the posted value becomes the CLIP return value of your exported function.

Function _CLIP_RETNL()

 _clip_retnl(ClipMachine * cm,long n) --> void

_clip_retnl() posts a numeric value into CLIP's return value area. When your exported function returns control to the calling CLIP program, the posted value becomes the CLIP return value of your exported function.

Function _CLIP_STORND()

Function _CLIP_STORNI()

 _clip_storni(ClipMachine * mp, int n, int num, int ind) --> int

Function _CLIP_STORNL()

 _clip_stornl(ClipMachine * mp, long n, int num, int ind) --> int