Archived Website:
This website is a static snapshot for archival purposes only.
It is no longer maintained or updated.
SWI-Prolog offers a powerful interface to C Kernighan &
Ritchie, 1978. The main design objectives of the foreign
language interface are flexibility and performance. A foreign predicate
is a C-function that has the same number of arguments as the predicate
represented. C-functions are provided to analyse the passed terms,
convert them to basic C-types as well as to instantiate arguments using
unification. Non-deterministic foreign predicates are supported,
providing the foreign function with a handle to control backtracking.
C can call Prolog predicates, providing both an query interface and
an interface to extract multiple solutions from an non-deterministic
Prolog predicate. There is no limit to the nesting of Prolog calling C,
calling Prolog, etc. It is also possible to write the `main' in C and
use Prolog as an embedded logical engine.
Section Index
6.3 Dynamic Linking of shared libraries
6.4 Using the library shlib for .DLL
and .so files
6.5 Interface Data types
6.6 The Foreign Include File
6.6.4 Constructing Terms
6.6.5 Unifying data
6.6.6 Calling Prolog from C
6.6.7 Discarding Data
6.6.8 Foreign Code and
Modules
6.6.9 Prolog exceptions in
foreign code
6.6.10 Foreign code and
Prolog threads
6.6.11 Catching Signals
(Software Interrupts)
6.6.12 Miscellaneous
6.6.13 Errors and warnings
6.6.14 Environment Control
from Foreign Code
6.6.15 Querying Prolog
6.6.16 Registering Foreign
Predicates
6.6.17 Foreign Code Hooks
6.6.18 Storing foreign data
6.6.19 Embedding SWI-Prolog
in other applications
6.7 Linking embedded applications using plld
6.8 The Prolog `home' directory
6.9 Example of Using the Foreign
Interface
6.10 Notes on Using Foreign Code