dev • api • name •


void GB.Post ( void (*func)() , long param )

Post a callback routine that will be called at the next event loop.

  • func is the address of the callback.

  • param is a long integer that will be pass to the callback.

Use this function if you can't execute a piece of code immediately.

For example, it is often dangerous to raise an event immediately, as the event handler may indirectly free some memory used by a function higher in the stack. So it is sometimes better to raise the event when you are on top of the event loop.

If you want to use an object in the callback, you must reference it with GB.Ref, to prevent the interpreter destroying it before the callback is called. And do not forget to call GB.Unref once you have finished with the object in the post routine!

For example, GB.Post is used for raising Click events when you select a menu, because raising the event immediately in the QT slot crashes the interpreter !

This function calls the post interpreter hook so that it knows that a new post routine has been registered.


// This is how menu event are sent in the QT component

static void send_menu_event(CMENU *menu)
  GB.Raise(menu, EVENT_Click, 0);
  GB.Unref((void **)&menu);

void CMenu::activated(int id)
  CMENU *menu = ... ;

  // Don't send the event immediately
  // GB.Raise(menu, EVENT_Click, NULL);

  GB.Post((void (*)())send_menu_event, (long)menu);

See also