SICStus Prolog provides several ways of interfacing with code written in other languages:
library(jsonrpc)(see lib-jsonrpc). It uses JSON in its process communication.
library(prologbeans)(see lib-prologbeans). It uses a custom protocol in its process communication.
The C side of the interface defines a number of functions and macros
for various operations. On the Prolog side, you have to supply
declarations specifying the names and argument/value types of C
functions being called as predicates. These declarations are used by
load_foreign_resource/1, which performs the
actual binding of functions to predicates. They are also needed when
the functions are unloaded, for example when SICStus is halted.
In most cases, the argument/value type declarations suffice for making the necessary conversions of data automatically as they are passed between C and Prolog. However, it is possible to declare the type of an argument to be a Prolog term, in which case the receiving function will see it as a “handle” object, called an SP_term_ref, for which access functions are provided.
The C support routines are available in a development system as well as in runtime systems. The support routines include:
In addition to the interface described in this chapter,
lib-structs and lib-objects) allow Prolog to hold pointers
to C data structures and arrays and access and store into fields in
those data structures in a very efficient way, allowing the programmer
to stay completely inside Prolog.
|• CPL Notes||Notes|
|• Calling C from Prolog||Calling C from Prolog|
|• Calling C++ from Prolog||Calling C++ from Prolog|
|• Support Functions||Support Functions|
|• Calling Prolog from C||Calling Prolog from C|
|• SICStus Streams||SICStus Streams|
|• Stand-Alone Executables||Stand-Alone Executables|
|• Mixing C and Prolog Examples||Mixing C and Prolog Examples|
|• Debugging Runtime Systems||Debugging Runtime Systems|