1.7 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 ofterm_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.