Next: Interfacing .NET and Java, Previous: Debug Intro, Up: Top [Contents][Index]
SICStus Prolog provides several ways of interfacing with code written in other languages:
library('jsonrpc/jsonrpc_server')
(see lib-jsonrpc). It
uses JSON in its process communication. This is probably the easiest
way to expose a Prolog program to a client written in some other
programming language.
library(prologbeans)
(see lib-prologbeans). It uses a
custom protocol in its process communication.
library(jasper)
(see lib-jasper).
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
the predicate 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:
foreign/[2,3]
declarations.
In addition to the interface described in this chapter,
library(structs)
and library(objects)
(see
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 |