Previous Up Next

Appendix D  Foreign C Interface

This library (loaded with :- lib(foreign)) allows to use external functions written for Quintus or SICStus Prolog, or to interface C functions which are independent of ECLiPSe. It accepts the syntax and semantics of the predicates foreign/3, load_foreign_files/2 and load_foreign_files/2 of Quintus/SICStus. Since their external interface is incompatible with the ECLiPSe one, this library generates a C source file which converts the ECLiPSeinterface into the foreign one, by defining a new C function for every C function defined in the foreign interface. Note that this approach uses more C code, but it is still more efficient than using a generic procedure to check the argument of every external function.

After compiling definitions of the foreign/3 predicate, (the predicate foreign_file/2 is ignored), the predicate make_simple_interface has to be called. This predicate generates a file interface.c, which contains the auxiliary C definitions. This file has to be compiled to obtain the interface.o file, it might also have to be edited to include other .h files. After the file interface.o has been generated, the system is fully compatible with the Quintus/SICStus foreign interface, and calling load_foreign_files/2 will connect the external functions with ECLiPSe.

Although it is possible to use this library to interface existing independent C functions, its main use is to port foreign interface from Quintus or SICStus. Please refer to their manuals for the description of the foreign interface.


Previous Up Next