… | |
… | |
27 | // perl bug #40256: perl does overwrite those with reentrant versions |
27 | // perl bug #40256: perl does overwrite those with reentrant versions |
28 | // but does not initialise their state structures. |
28 | // but does not initialise their state structures. |
29 | #undef random |
29 | #undef random |
30 | #undef crypt |
30 | #undef crypt |
31 | |
31 | |
32 | struct pl; |
|
|
33 | struct object; |
|
|
34 | struct mapstruct; |
|
|
35 | |
|
|
36 | void cfperl_init (); |
32 | void cfperl_init (); |
37 | void cfperl_boot (); |
33 | void cfperl_boot (); |
38 | void cfperl_main (); |
34 | void cfperl_main (); |
39 | |
|
|
40 | // could have used templates, but a more traditional C api |
|
|
41 | // uses more explicit typing which is ok for this purpose. |
|
|
42 | enum data_type |
|
|
43 | { |
|
|
44 | DT_END, // no further arguments |
|
|
45 | DT_AV, // perl-only av that needs to be flattened out |
|
|
46 | DT_INT, |
|
|
47 | DT_INT64, |
|
|
48 | DT_DOUBLE, |
|
|
49 | DT_STRING, // 0-terminated string |
|
|
50 | DT_DATA, // string + length |
|
|
51 | DT_OBJECT, |
|
|
52 | DT_MAP, |
|
|
53 | DT_PLAYER, |
|
|
54 | DT_ARCH, |
|
|
55 | DT_PARTY, |
|
|
56 | DT_REGION, |
|
|
57 | |
|
|
58 | NUM_DATA_TYPES |
|
|
59 | }; |
|
|
60 | |
35 | |
61 | enum event_klass |
36 | enum event_klass |
62 | { |
37 | { |
63 | KLASS_NONE, |
38 | KLASS_NONE, |
64 | KLASS_GLOBAL, |
39 | KLASS_GLOBAL, |
… | |
… | |
128 | // derive using the curiously recurring template pattern, to avoid |
103 | // derive using the curiously recurring template pattern, to avoid |
129 | // virtual method calls etc. |
104 | // virtual method calls etc. |
130 | template<class subclass> |
105 | template<class subclass> |
131 | struct attachable : attachable_base |
106 | struct attachable : attachable_base |
132 | { |
107 | { |
133 | static data_type get_dt () |
|
|
134 | { |
|
|
135 | return subclass::get_dt (); |
|
|
136 | } |
|
|
137 | |
|
|
138 | void instantiate () |
108 | void instantiate () |
139 | { |
109 | { |
140 | if (attach) |
110 | if (attach) |
141 | attachable_base::instantiate (get_dt (), static_cast<subclass *>(this)); |
111 | attachable_base::instantiate ((data_type) cftype<subclass>::dt, static_cast<subclass *>(this)); |
142 | } |
112 | } |
143 | }; |
113 | }; |
144 | |
114 | |
145 | struct object_freezer |
115 | struct object_freezer |
146 | { |
116 | { |
… | |
… | |
154 | |
124 | |
155 | template<class subclass> |
125 | template<class subclass> |
156 | void put (attachable<subclass> *obj) |
126 | void put (attachable<subclass> *obj) |
157 | { |
127 | { |
158 | put ((attachable_base *)obj); |
128 | put ((attachable_base *)obj); |
|
|
129 | } |
|
|
130 | |
|
|
131 | void put (keyword k); |
|
|
132 | void put (const char *v); |
|
|
133 | void put (int v); |
|
|
134 | |
|
|
135 | template<typename value> |
|
|
136 | void put (keyword k, value v) |
|
|
137 | { |
|
|
138 | put (k); |
|
|
139 | put (v); |
159 | } |
140 | } |
160 | |
141 | |
161 | bool save (const char *filename); |
142 | bool save (const char *filename); |
162 | |
143 | |
163 | operator bool () { return !!av; } |
144 | operator bool () { return !!av; } |
… | |
… | |
188 | |
169 | |
189 | template<class subclass> |
170 | template<class subclass> |
190 | void get (attachable<subclass> *obj, int oid) |
171 | void get (attachable<subclass> *obj, int oid) |
191 | { |
172 | { |
192 | if (av) |
173 | if (av) |
193 | get (subclass::get_dt (), (subclass *)obj, obj, oid); |
174 | get ((data_type) cftype<subclass>::dt, (subclass *)obj, obj, oid); |
194 | } |
175 | } |
195 | |
176 | |
196 | token get_token (); |
177 | token get_token (); |
197 | |
178 | |
198 | operator FILE *() { return fp; } |
179 | operator FILE *() { return fp; } |