13.3. C-API

About
Functions order

13.3.1. About C-API

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

#

13.3.2. C-API functions order