2.15 The PREDICATE and PREDICATE_NONDET macros (version 2)
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 2)
          • The PREDICATE and PREDICATE_NONDET macros (version 2)
            • Variations of the PREDICATE macro (version 2)
            • Non-deterministic predicates (version 2)
            • Controlling the Prolog destination module (version 2)

2.15.3 Controlling the Prolog destination module (version 2)

With no special precautions, the predicates are defined into the module from which load_foreign_library/1 was called, or in the module user if there is no Prolog context from which to deduce the module such as while linking the extension statically with the Prolog kernel.

Alternatively, before loading the SWI-Prolog include file, the macro PROLOG_MODULE may be defined to a string containing the name of the destination module. A module name may only contain alpha-numerical characters (letters, digits, _). See the example below:

#define PROLOG_MODULE "math"
#include <SWI-Prolog.h>
#include <math.h>

PREDICATE(pi, 1)
{ A1 = M_PI;
}
?- math:pi(X).

X = 3.14159