Overview

The Foreign Language Interface is the protocol by which you can call functions written in other programming languages from Prolog (see fli-p2f), and by which you can call Prolog predicates from C (see fli-ffp).

In both cases you have to supply declarations in Prolog specifying the argument types of the function/predicate being called. This is necessary so that the Prolog system can automatically make the necessary transformations of data as they are passed between the languages. The declarations are compiled into special abstract machine instructions in order to minimize the cost of inter-language calls.

It is possible to specify that an argument is a Prolog term. In this case a foreign function receiving such a term sees it as a special kind of object called a QP_term_ref. A set of functions is provided that allow foreign functions to manipulate terms via these QP_term_refs. Term passing is described in fli-p2f-trm and fli-ffp-a2s-trm. The functions for manipulating terms are described in cfu.

Some kinds of data are not best represented in Prolog. It is better to keep such data in foreign data structures and just pass pointers to these structures to Prolog. Given such pointers, Prolog arithmetic predicates such as is/2 and =:=/2 allow access to foreign data; see ref-ari-aex. Foreign data can also be modified directly from Prolog using assign/2, which is described in cfu.

Input/Output operations on Prolog streams can be performed in C. Functions, macros and variables for this purpose are summarized in fli-ios-bio. The I/O system has been designed to make it maximally customizable at the C level. The kinds of customization that you might want to do are to create a stream to read from or write to a socket, or to create a stream to read from an encrypted file. The C level of the I/O system is described in fli-ios.

A number of functions are defined to aid in embedding Prolog programs into other software systems. These functions all begin with the letters QU and they are defined in fli-emb. The source of these functions is provided with the system, and you may define your own versions to replace them. To do this you will need to link your routines with the development system to make your own customized version of the development system. How to do this is described in sap.