defs.h
Go to the documentation of this file.
1 #ifndef NVIM_EVENT_DEFS_H
2 #define NVIM_EVENT_DEFS_H
3 
4 #include <assert.h>
5 #include <stdarg.h>
6 
7 #define EVENT_HANDLER_MAX_ARGC 10
8 
9 typedef void (*argv_callback)(void **argv);
10 typedef struct message {
13 } Event;
14 typedef void(*event_scheduler)(Event event, void *data);
15 
16 #define VA_EVENT_INIT(event, h, a) \
17  do { \
18  assert(a <= EVENT_HANDLER_MAX_ARGC); \
19  (event)->handler = h; \
20  if (a) { \
21  va_list args; \
22  va_start(args, a); \
23  for (int i = 0; i < a; i++) { \
24  (event)->argv[i] = va_arg(args, void *); \
25  } \
26  va_end(args); \
27  } \
28  } while (0)
29 
30 static inline Event event_create(argv_callback cb, int argc, ...)
31 {
33  Event event;
34  VA_EVENT_INIT(&event, cb, argc);
35  return event;
36 }
37 
38 #endif // NVIM_EVENT_DEFS_H
Definition: defs.h:10
#define VA_EVENT_INIT(event, h, a)
Definition: defs.h:16
void * argv[EVENT_HANDLER_MAX_ARGC]
Definition: defs.h:12
void(* event_scheduler)(Event event, void *data)
Definition: defs.h:14
assert(len >=0)
struct message Event
argv_callback handler
Definition: defs.h:11
void(* argv_callback)(void **argv)
Definition: defs.h:9
#define EVENT_HANDLER_MAX_ARGC
Definition: defs.h:7