we now have lamda expressions (anonymous functions)

This commit is contained in:
overflowerror 2018-02-08 23:51:10 +01:00
parent 325da7fe62
commit de2946c9fa
2 changed files with 9 additions and 23 deletions

View file

@ -6,36 +6,20 @@
BOOT(init);
void eventHandler(event_t event) {
fprintf(stderr, "Got event %d.\n", event);
}
void shutdownHandler(event_t event) {
fprintf(stderr, "Shuting down.\n");
}
void intervalHandler() {
static int count = 0;
count++;
fprintf(stderr, "interval count %d.\n", count);
if (count > 4) {
fprintf(stderr, "Provoking error.\n");
boot.events.enableSignal(SHUTDOWN); // SHUTDOWN is not a signal
}
}
void init() {
printf("Hello World!\n");
boot.mode = WAIT;
boot.debug = true;
boot.events.addEventListener(SHUTDOWN, shutdownHandler);
boot.events.addEventListener(SIGUSR1, eventHandler);
boot.events.addEventListener(SHUTDOWN, lambda(void, (event_t event) {
fprintf(stderr, "Shuting down.\n");
}));
boot.events.addEventListener(SIGUSR1, lambda(void, (event_t event) {
fprintf(stderr, "Got SIGUSR1.\n");
}));
boot.events.enableSignal(SIGUSR1);
timer_t timer = boot.time.createSignalTimer(SIGUSR1);
boot.time.startTimer(timer, 5000);
timer_t interval = boot.time.createThreadTimer(&intervalHandler);
boot.time.startInterval(interval, 2000);
boot.time.startTimer(timer, 1000);
}

View file

@ -4,6 +4,8 @@
#include <stdbool.h>
#include <time.h>
#define lambda(r, f) ({r __fn__ f __fn__; })
#define EXIT_SUCCESS 0
#define EXIT_ERROR 3