Next: Calling C++ from Prolog, Previous: CPL Notes, Up: Mixing C and Prolog [Contents][Index]
Functions written in the C language may be called from Prolog using an interface in which automatic type conversions between Prolog terms and common C types are declared as Prolog facts. Calling without type conversion can also be specified, in which case the arguments and values are passed as SP_term_refs. This interface is partly modeled after Quintus Prolog.
The functions installed using this foreign language interface may invoke Prolog code and use the support functions described in the other sections of this chapter.
Functions, or their equivalent, in any other language having C compatible calling conventions may also be interfaced using this interface. When referring to C functions in the following, we also include such other language functions. Note however that a C compiler is needed since a small amount of glue code (in C) must be generated for interfacing purposes.
As an alternative to this interface,
SP_define_c_predicate()
defines a Prolog predicate such
that when the Prolog predicate is called it will call a C function
with a term corresponding to the Prolog goal. For details,
see cpg-ref-SP_define_c_predicate.
• Foreign Resources | Foreign Resources | |
• Conversion Declarations | Conversion Declarations | |
• Conversions between Prolog Arguments and C Types | Conversions between Prolog Arguments and C Types | |
• Interface Predicates | Interface Predicates | |
• The Foreign Resource Linker | The Foreign Resource Linker | |
• Init and Deinit Functions | Init and Deinit Functions | |
• Creating the Linked Foreign Resource | Creating the Linked Foreign Resource | |
• Foreign Code Examples | Foreign Code Examples |