• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

A C++ interface to SWI-Prolog
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • Introduction
        • Overview
        • Examples
        • The class PlTerm
        • The class PlTermv
        • Supporting Prolog constants
        • The class PlRegister
        • The class PlQuery
        • The PREDICATE macro
        • Exceptions
        • Embedded applications
        • Considerations
        • Conclusions

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

ClioPatria (version V3.1.1-21-gb8003bb)