next up previous contents index
Next: Foreign Code Hooks Up: The Foreign Include File Previous: Querying Prolog   Contents   Index

Registering Foreign Predicates

intPL_register_foreignconst char *name, int arity, foreign_t (*function)(), int flags Register a C-function to implement a Prolog predicate. After this call returns successfully a predicate with name name (a char *) and arity arity (a C int) is created. As a special case, name may consist of a sequence of alpha-numerical characters followed by the colon (). In this case the name uptil the colon is taken to be the destination module and the rest of the name the predicate name.

When called in Prolog, Prolog will call function. flags forms bitwise or'ed list of options for the installation. These are:

PL_FA_NOTRACE Predicate cannot be seen in the tracer
PL_FA_TRANSPARENT Predicate is module transparent
PL_FA_NONDETERMINISTIC Predicate is non-deterministic. See also PL_retry.
PL_FA_VARARGS Use alternative calling convention.

voidPL_load_extensionsPL_extension *e Register foreign predicates from a table of structures. This is an alternative to multiple calls to PL_register_foreign and simplifies code that wishes to use PL_register_extensions as an alternative. The type PL_extension is defined as:


\begin{code}
typedef struct _PL_extension
{ char *predicate_name; /* Name of the...
...ting functions */
short flags; /* Or of PL_FA_... */
} PL_extension;
\end{code}

voidPL_register_extensionsPL_extension *e The function PL_register_extensions behaves as PL_load_extensions, but is the only PL_* function that may be called before PL_initialise. The predicates are registered into the module user after registration of the SWI-Prolog builtin foreign predicates and before loading the initial saved state. This implies that initialization1 directives can refer to them.

Here is an example of its usage:


\begin{code}
static PL_extension predicates[] = {
{ ''foo'', 1, pl_foo, 0 },
{ '...
...ates);
\par if ( !PL_initialise(argc, argv) )
PL_halt(1);
\par ...
}
\end{code}


next up previous contents index
Next: Foreign Code Hooks Up: The Foreign Include File Previous: Querying Prolog   Contents   Index
Dr. Richard Botting 2001-12-12