1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
24 | // cfperl.h perl interface |
24 | // cfperl.h perl interface |
25 | // |
25 | // |
26 | #ifndef CFPERL_H__ |
26 | #ifndef CFPERL_H__ |
27 | #define CFPERL_H__ |
27 | #define CFPERL_H__ |
28 | |
28 | |
29 | #include <cstdarg> |
|
|
30 | #include <cstdio> |
|
|
31 | #include <bitset> |
|
|
32 | |
|
|
33 | using namespace std; |
29 | using namespace std; |
34 | |
30 | |
35 | #include <EXTERN.h> |
31 | #include <EXTERN.h> |
36 | #include <perl.h> |
32 | #include <perl.h> |
37 | #include <XSUB.h> |
33 | #include <XSUB.h> |
… | |
… | |
85 | LOG (llevError, "runtime error in %s: %s", __func__, SvPVutf8_nolen (ERRSV)); |
81 | LOG (llevError, "runtime error in %s: %s", __func__, SvPVutf8_nolen (ERRSV)); |
86 | |
82 | |
87 | inline int call_pvsv (const char *ob, I32 flags) { return call_pv (ob, flags); } |
83 | inline int call_pvsv (const char *ob, I32 flags) { return call_pv (ob, flags); } |
88 | inline int call_pvsv (SV *ob, I32 flags) { return call_sv (ob, flags); } |
84 | inline int call_pvsv (SV *ob, I32 flags) { return call_sv (ob, flags); } |
89 | |
85 | |
|
|
86 | // TODO: temporarily enabled pushstack/popstack for all calls from the core, to maybe fix object memleak? |
|
|
87 | #define CALL_PUSH PUSHSTACKi (PERLSI_UNKNOWN) |
|
|
88 | #define CALL_POP PUTBACK; POPSTACK; SPAGAIN |
90 | #define CALL_BEGIN(args) dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args) |
89 | #define CALL_BEGIN(args) dSP; CALL_PUSH; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args) |
91 | #define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc |
90 | #define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc |
92 | #define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr))) |
91 | #define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr))) |
93 | #define CALL_CALL(name, flags) PUTBACK; int count = call_pvsv (name, (flags) | G_EVAL); SPAGAIN; |
92 | #define CALL_CALL(name, flags) PUTBACK; int count = call_pvsv (name, (flags) | G_EVAL); SPAGAIN; |
94 | #define CALL_END PUTBACK; CHECK_ERROR; FREETMPS; LEAVE |
93 | #define CALL_END PUTBACK; CHECK_ERROR; FREETMPS; LEAVE; CALL_POP |
95 | |
94 | |
96 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
95 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
97 | |
96 | |
98 | void cfperl_init (); |
97 | void cfperl_init (); |
99 | void cfperl_main (); |
98 | void cfperl_main (); |
… | |
… | |
214 | MTH void destroy (); |
213 | MTH void destroy (); |
215 | |
214 | |
216 | // return wether an object was destroyed already |
215 | // return wether an object was destroyed already |
217 | MTH bool destroyed () const { return attachable_flags & F_DESTROYED; } |
216 | MTH bool destroyed () const { return attachable_flags & F_DESTROYED; } |
218 | |
217 | |
|
|
218 | // destruct and free the memory for this object |
|
|
219 | virtual void do_delete (); |
|
|
220 | |
219 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
221 | virtual void gather_callbacks (AV *&callbacks, event_type event) const; |
220 | |
222 | |
221 | #if 0 |
223 | #if 0 |
222 | private: |
224 | private: |
223 | static refcounted *rc_first; |
225 | static refcounted *rc_first; |
… | |
… | |
254 | set_key (key, value, 0); |
256 | set_key (key, value, 0); |
255 | } |
257 | } |
256 | |
258 | |
257 | attachable &operator =(const attachable &src); |
259 | attachable &operator =(const attachable &src); |
258 | |
260 | |
259 | // used to _quickly_ device wether to shortcut the evaluation |
261 | // used to _quickly_ decide wether to shortcut the evaluation |
260 | bool should_invoke (event_type event) |
262 | bool should_invoke (event_type event) |
261 | { |
263 | { |
262 | return ev_want_event [event] || cb; |
264 | return ev_want_event [event] || cb; |
263 | } |
265 | } |
264 | |
266 | |
… | |
… | |
287 | extern struct global gbl_ev; |
289 | extern struct global gbl_ev; |
288 | |
290 | |
289 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
291 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
290 | |
292 | |
291 | // a little dirty hack, maybe unify with something else at a later time |
293 | // a little dirty hack, maybe unify with something else at a later time |
|
|
294 | // it is used to communicate as much info about the keyword string |
|
|
295 | // to the consuemr as possible, for maximum performance. |
292 | struct keyword_string |
296 | struct keyword_string |
293 | { |
297 | { |
294 | const char *s; |
298 | const char *s; |
295 | const int l; |
299 | const int l; |
296 | |
300 | |