1 A C++ interface to SWI-Prolog
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog
          • Summary of changes between Versions 1 and 2
          • A simple example
          • Sample code
          • Introduction
          • The life of a PREDICATE
          • Overview
          • Examples
          • Rationale for changes from version 1
          • Porting from version 1 to version 2
          • The class PlFail
          • Overview of accessing and changing values
          • The class PlRegister
          • The class PlQuery
          • The PREDICATE and PREDICATE_NONDET macros
          • Exceptions
          • Embedded applications
          • Considerations
          • Conclusions

1.12 The class PlRegister

This class encapsulates PL_register_foreign(). It is defined as a class rather then a function to exploit the C++ global constructor feature. This class provides a constructor to deal with the PREDICATE() way of defining foreign predicates as well as constructors to deal with more conventional foreign predicate definitions.

PlRegister :: PlRegister(const char *module, const char *name, int arity, foreign_t (f)(term_t t0, int a, control_t ctx))
Register f as a the implementation of the foreign predicate <name>/<arity>. This interface uses the PL_FA_VARARGS calling convention, where the argument list of the predicate is passed using an array of term_t objects as returned by PL_new_term_refs(). This interface poses no limits on the arity of the predicate and is faster, especially for a large number of arguments.
PlRegister :: PlRegister(const char *module, const char *name, foreign_t (*f)(PlTerm a0, ...)
Registers functions for use with the traditional calling conventional, where each positional argument to the predicate is passed as an argument to the function f. This can be used to define functions as predicates similar to what is used in the C-interface:
static foreign_t
pl_hello(PlTerm a1)
{ ...
}

PlRegister x_hello_1(NULL, "hello", 1, pl_hello);

This construct is currently supported upto 3 arguments.