1 |
// |
2 |
// cfperl.h perl interface |
3 |
// |
4 |
#ifndef CFPERL_H__ |
5 |
#define CFPERL_H__ |
6 |
|
7 |
// could have used templates, but a more traditional C api |
8 |
// uses more explicit typing which is ok for this purpose. |
9 |
enum data_type { |
10 |
DT_END, // no further arguments |
11 |
DT_INT, |
12 |
DT_LONG, |
13 |
DT_DOUBLE, |
14 |
DT_STRING, // 0-terminated string |
15 |
DT_DATA, // string + length |
16 |
DT_OBJECT, |
17 |
DT_MAP, |
18 |
DT_PLAYER, |
19 |
DT_ARCH, |
20 |
DT_PARTY, |
21 |
DT_REGION, |
22 |
}; |
23 |
|
24 |
enum event_klass { |
25 |
KLASS_GLOBAL, |
26 |
KLASS_PLAYER, |
27 |
KLASS_OBJECT, |
28 |
KLASS_MAP, |
29 |
}; |
30 |
|
31 |
enum event_type { |
32 |
# define def(klass,name) EV_ ## klass ## name, |
33 |
# include "eventinc.h" |
34 |
# undef def |
35 |
NUM_EVENT_TYPES |
36 |
}; |
37 |
|
38 |
#define ARG_INT(v) DT_INT , static_cast<int> (v) |
39 |
#define ARG_LONG(v) DT_LONG , static_cast<long> (v) |
40 |
#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) |
41 |
#define ARG_STRING(v) DT_STRING, static_cast<char *> (v) |
42 |
#define ARG_DATA(s,l) DT_DATA , static_cast<void *> (s), (l) |
43 |
#define ARG_OBJECT(o) DT_OBJECT, static_cast<struct object *> (o) |
44 |
#define ARG_MAP(o) DT_MAP , static_cast<struct mapstruct *> (o) |
45 |
#define ARG_PLAYER(o) DT_PLAYER, static_cast<struct pl *> (o) |
46 |
#define ARG_ARCH(o) DT_ARCH , static_cast<struct archetype *> (o) |
47 |
#define ARG_PARTY(o) DT_PARTY , static_cast<struct party *> (o) |
48 |
#define ARG_REGION(o) DT_REGION, static_cast<struct region *> (o) |
49 |
|
50 |
// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
51 |
|
52 |
// all these return true when the normal event processing should be skipped (if any) |
53 |
#define INVOKE(klass, event, ...) cfperl_invoke (EV_ ## klass ## event, ## __VA_ARGS__, DT_END) |
54 |
|
55 |
#define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__) |
56 |
#define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__) |
57 |
#define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__) |
58 |
#define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__) |
59 |
|
60 |
bool cfperl_invoke (event_type event, ...); |
61 |
void cfperl_free_ob (object *op); |
62 |
|
63 |
void cfperl_init (); |
64 |
void cfperl_main (); |
65 |
|
66 |
#endif |
67 |
|