Normally this is done after a first call from Prolog to C (this gives a chance to the prolog system to get initialized). The most flexible technique is based on multiple engines. Take a look at case 11 and case 12 in the previous section.
The lower-level interface, (which follows) is still usable but less recommended.
/* this can be used to call Prolog from C : see example if0 */ term bp_prolog_call(goal,regs,H,P,A,wam) register term goal,regs,H,*A; register instr P; register stack wam; { PREP_CALL(goal); return bp(regs,H,P,A,wam); } /* simple example of prolog call */ term if0(regs,H,P,A,wam) register term regs,H,*A; register instr P; register stack wam; { term bp(); cell goal=regs[1]; /* in this example the input GOAL is in regs[1] */ /* of course you can also build it directly in C */ /* unless you want specific action on failure, use BP_prolog_call(goal) here */ H=bp_prolog_call(goal,regs,H,P,A,wam); if(H) fprintf(stderr,"success: returning from New WAM\n"); else fprintf(stderr,"fail: returning from New WAM\n"); /* do not forget this !!! */ return H; /* return NULL to signal failure */ }
BinProlog's main() should be the starting point of your program to be able to initialize all data areas. To call back from C you can follow the example if0. A sustained BinProlog-C dialog can be set up by using the 2 techniques described previously.
An example of using the C-interface (composed of files c.h c.c c.pl) can be found in directory c_inter. If you whish you can create a standalone C-executable by using BinProlog's compilation to C (see directories pl2c, dynpl2c) you can simply type `make' in directory c_inter.