Registering predicates defined in C

The following function registers a predicate that is defined by a C function.
       insert_cpred(char *name, int arity, int (*func)())
The first argument is the predicate name, the second argument is the arity, and the third argument is the name of the function that defines the predicate. The function that defines the predicate cannot take any argument. As described above, the function bp_get_call_arg(i,arity) is used to fetch arguments from the Prolog call.

For example, the following registers a predicate whose name is "p" and whose arity is 2.

       extern int p();	
       insert_cpred("p", 2, p)
The C function's name does not need to be the same as the predicate's name.

Predicates that are defined in C should be registered after the Prolog engine is initialized, and before any call is executed. One good place for registering predicates is the Cboot() function in the file cpreds.c, which registers all of the built-ins of B-Prolog.



Neng-Fa Zhou 2013-01-25