Top |
The Interrupt HandlerThe Interrupt Handler — Specifying an interrupt handler for cleaning up critical resources |
Most platforms have some provision for interrupting a program — command+period on the Macintosh, control+C in Unix, possibly a window manager item, or other possibilities. This can happen at any time, including while execution is nested inside one of your own functions, or inside a Glk library function.
If you need to clean up critical resources, you can specify an interrupt handler function.
void
glk_set_interrupt_handler (void (*func) (void)
);
Sets func
to be the interrupt handler. func
should be a pointer to a
function which takes no argument and returns no result. If Glk receives an
interrupt, and you have set an interrupt handler, your handler will be
called, before the process is shut down.
Initially there is no interrupt handler. You can reset to not having any by
calling glk_set_interrupt_handler(NULL)
.
If you call glk_set_interrupt_handler()
with a new handler function while an
older one is set, the new one replaces the old one. Glk does not try to queue
interrupt handlers.
You should not try to interact with the player in your interrupt handler. Do
not call glk_select()
or glk_select_poll()
. Anything you print to a window
may not be visible to the player.