Registering predicates defined in C

The following function registers a predicate defined by a C function.
       insert_cpred(char *name, int arity, int (*func)())
The first argument is the predicate name, the second is the arity, and the third is the name of the function that defines the predicate. The function cannot take any argument. As described before, 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 name.

Predicates 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 the built-ins of B-Prolog.



Neng-Fa Zhou 2012-01-03