[Up] [Contents] [Index] [Summary]

5.6.15 Foreign Code Hooks

For various specific applications some hooks re provided.

PL_dispatch_hook_t PL_dispatch_hook(PL_dispatch_hook_t)
If this hook is not NULL, this function is called when reading from the terminal. It is supposed to dispatch events when SWI-Prolog is connected to a window environment. It can return two values: PL_DISPATCH_INPUT indicates Prolog input is available on file descriptor 0 or PL_DISPATCH_TIMEOUT to indicate a timeout. The old hook is returned. The type PL_dispatch_hook_t is defined as:

typedef int (*PL_dispatch_hook_t)(void);

void PL_abort_hook(PL_abort_hook_t)
Install a hook when abort/0 is executed. SWI-Prolog abort/0 is implemented using C setjmp()/longjmp() construct. The hooks are executed in the reverse order of their registration after the longjmp() took place and before the Prolog toplevel is reinvoked. The type PL_abort_hook_t is defined as: typedef void (*PL_abort_hook_t)(void);

int PL_abort_unhook(PL_abort_hook_t)
Remove a hook installed with PL_abort_hook(). Returns FALSE if no such hook is found, TRUE otherwise.

void PL_reinit_hook(PL_reinit_hook_t)
Install a hook that is called when a saved program (using save_program/[1,2]) is restored. The hooks are called in reverse order. The type PL_reinit_hook_t is defined as: typedef void (*PL_reinit_hook_t)(int argc, char **argv);

int PL_reinit_unhook(PL_reinit_hook_t)
Remove a hook installed with PL_reinit_hook(). Returns FALSE if no such hook is found, TRUE otherwise.