dev • api • name • gb.hook


void *GB.Hook ( int type , void *hook )

Installs a global interpreter hook.

  • type is an integer constant that identifies the hook.

  • hook is the hook function pointer.

The GB.Hook function returns the previous hook, so that you can call it yourself if necessary. I think this is useful only to the GB_HOOK_MAIN hook.

There are eight global hooks:



void hook_main ( int *argc, char **argv )

This hook is called to parse the command line.

  • argc is a pointer to the number of arguments.

  • argv is an array of strings containing the arguments, like the one received by the main function.

If you consume process arguments in argv, then you have to remove them from it and modify *argc accordingly.


int hook_loop ( void )

This hook is called to enter the event loop until the program ends.

The return value should be the value that must be returned by the program.


void hook_wait ( long duration )

This hook is called to implement the WAIT instruction.

You must watch the event loop at most during the number of milliseconds specified by duration, and then return.


void hook_timer ( GB_TIMER *timer, int enabled )

This hook is called to start or stop a timer.

  • timer points at the timer object. All needed information is found inside.

  • enabled is TRUE is the timer must be activated, or FALSE if it must be stopped.

The GB_TIMER structure includes a field named id, that you have to set to a number that uniquely identifies the timer. This identifier must be reset to zero when the timer is stopped.


void hook_lang ( char *lang , int rtl )

This hook is called when the current language changes.

  • lang is the new language set

  • rtl will tell you if this language is right-to-left written.


void hook_watch ( int fd , int type , void *callback , long param )

This hook is called to implement the watch of file descriptors.

  • fd is the file descriptor to watch.

  • type is one of the constants specified in /wiki/api/cat/watch.

  • param is the parameter registered when calling GB.Watch.


void hook_post ( void )

This hook is called to execute callback functions at the next call of the event loop.


void hook_quit ( void )

This hook is called when the QUIT instruction is used.

You should clean and release everything you can.


void hook_error ( int code , char *error , char *where )

This hook is called to display error messages.

  • code is the error code.

  • error is the error message.

  • where is a string that describes where the error occured.

See also