Summary of steps

Following is a summary of the steps that enable you to call a Prolog predicate from a C function:


IN THE PROLOG CODE:
  1. Use extern/1 to declare the predicate callable from foreign functions, establishing an argument passing interface (see fli-ffp-ppc).

IN THE C CODE:
  1. Look up the Prolog predicate by calling one of the functions QP_predicate() or QP_pred(). This provides C with a "handle" on the Prolog predicate that is used to make the actual call. (see fli-ffp-ccp-lcp).
  2. If only a single solution is required, the predicate handle, together with C variables for input and output parameters, is passed to QP_query(). If QP_query() returns successfully, output results will have been left in C variables according to the specified interface.
  3. If more than one solution is required, the predicate handle and C variables for input and output parameters are passed to QP_open_query(). This function initiates a query, returning a query identifier, which is passed to QP_next_solution(), which is called once for each solution requested. When a solution is returned, output results are left in C variables according to the specified interface. When sufficient solutions have been returned, or there are no more solutions, the query identifier is passed to either QP_cut_query() or QP_close_query() to terminate the query.