diff --git a/GNUmakefile b/GNUmakefile index 92c8bc93..f0e1f055 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -25,6 +25,7 @@ baseHFILES = \ baseCFILES = \ box.c \ ptrarray.c \ + shouldquit.c \ $(osCFILES) baseMFILES = $(osMFILES) diff --git a/shouldquit.c b/shouldquit.c new file mode 100644 index 00000000..27805df8 --- /dev/null +++ b/shouldquit.c @@ -0,0 +1,22 @@ +// 9 may 2015 +#include "ui.h" +#include "uipriv.h" + +static int defaultOnShouldQuit(void *data) +{ + return 0; +} + +static int (*onShouldQuit)(void *) = defaultOnShouldQuit; +static void *onShouldQuitData; + +void uiOnShouldQuit(int (*f)(void *), void *data) +{ + onShouldQuit = f; + onShouldQuitData = data; +} + +int shouldQuit(void) +{ + return (*onShouldQuit)(onShouldQuitData); +} diff --git a/ui.idl b/ui.idl index 8b442408..41e76b88 100644 --- a/ui.idl +++ b/ui.idl @@ -24,6 +24,8 @@ func FreeInitError(err *const char); func Main(void); func Quit(void); +func OnShouldQuit(f *func(data *void) int, data *void); + func FreeText(text *char); raw "typedef struct uiSizingSys uiSizingSys;"; diff --git a/uipriv.h b/uipriv.h index ed2ef272..17493d9d 100644 --- a/uipriv.h +++ b/uipriv.h @@ -27,3 +27,6 @@ void ptrArrayAppend(struct ptrArray *, void *); void ptrArrayInsertBefore(struct ptrArray *, uintmax_t, void *); void ptrArrayDelete(struct ptrArray *, uintmax_t); #define ptrArrayIndex(p, T, i) ((T) ((p)->ptrs[(i)])) + +// shouldquit.c +int shouldQuit(void);