ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
(Generate patch)

Comparing deliantra/server/include/cfperl.h (file contents):
Revision 1.41 by root, Mon Dec 25 11:25:49 2006 UTC vs.
Revision 1.42 by root, Sat Dec 30 10:16:10 2006 UTC

11#include <EXTERN.h> 11#include <EXTERN.h>
12#include <perl.h> 12#include <perl.h>
13#include <XSUB.h> 13#include <XSUB.h>
14 14
15#include <EventAPI.h> 15#include <EventAPI.h>
16#include <CoroAPI.h>
16 17
18#include "util.h"
19#include "keyword.h"
20#include "dynbuf.h"
17#include "callback.h" 21#include "callback.h"
22
23//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 24
19// optimisations/workaround for functions requiring my_perl in scope (anti-bloat) 25// optimisations/workaround for functions requiring my_perl in scope (anti-bloat)
20#undef localtime 26#undef localtime
21#undef srand48 27#undef srand48
22#undef drand48 28#undef drand48
28#undef strerror 34#undef strerror
29 35
30// same here, massive symbol spamming 36// same here, massive symbol spamming
31#undef do_open 37#undef do_open
32#undef do_close 38#undef do_close
39#undef ref
33 40
34// perl bug #40256: perl does overwrite those with reentrant versions 41// perl bug #40256: perl does overwrite those with reentrant versions
35// but does not initialise their state structures. 42// but does not initialise their state structures.
36#undef random 43#undef random
37#undef crypt 44#undef crypt
38 45
46//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47
48// some macros to simplify perl in-calls
49
50// FUNCTION is, afaik, a gnu extension
51#define CHECK_ERROR \
52 if (SvTRUE (ERRSV)) \
53 LOG (llevError, "runtime error in %s: %s\n", __func__, SvPVutf8_nolen (ERRSV));
54
55#define CALL_BEGIN(args) dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args)
56#define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc
57#define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr)))
58#define CALL_CALL(name, flags) PUTBACK; int count = call_pv (name, (flags) | G_EVAL); SPAGAIN;
59#define CALL_END CHECK_ERROR; FREETMPS; LEAVE
60
61//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62
39void cfperl_init (); 63void cfperl_init ();
40void cfperl_main (); 64void cfperl_main ();
65
66//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67
68// virtual server time, excluding time jumps and lag
69extern double runtime;
41 70
42enum event_klass 71enum event_klass
43{ 72{
44 KLASS_NONE, 73 KLASS_NONE,
45 KLASS_GLOBAL, 74 KLASS_GLOBAL,
89#define RESULT_INT(idx) RESULT(idx, INT) 118#define RESULT_INT(idx) RESULT(idx, INT)
90 119
91double cfperl_result_DOUBLE (int idx); 120double cfperl_result_DOUBLE (int idx);
92int cfperl_result_INT (int idx); 121int cfperl_result_INT (int idx);
93 122
123//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124
94struct attachable 125struct attachable
95{ 126{
127 static MGVTBL vtbl;
128
96 static unordered_vector<attachable *> mortals; 129 static unordered_vector<attachable *> mortals;
97 static void check_mortals (); 130 static void check_mortals ();
98 131
99 enum { 132 enum {
100 F_DESTROYED = 0x01, 133 F_DESTROYED = 0x01,
164{ 197{
165 void gather_callbacks (AV *&callbacks, event_type event) const; 198 void gather_callbacks (AV *&callbacks, event_type event) const;
166}; 199};
167 200
168extern struct global gbl_ev; 201extern struct global gbl_ev;
202
203//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
169 204
170struct object_freezer : dynbuf 205struct object_freezer : dynbuf
171{ 206{
172 AV *av; 207 AV *av;
173 208
303struct object_thawer 338struct object_thawer
304{ 339{
305 SV *text; // text part 340 SV *text; // text part
306 AV *av; // perl part 341 AV *av; // perl part
307 char *line; // current beginning of line 342 char *line; // current beginning of line
308 char *last_value; 343 char *last_keyword, *last_value;
309 344
310 operator bool () { return !!text; } 345 operator bool () { return !!text; }
311 346
312 object_thawer (const char *filename = 0); 347 object_thawer (const char *filename = 0);
313 object_thawer (const char *data, AV *perlav); 348 object_thawer (const char *data, AV *perlav);
314 ~object_thawer (); 349 ~object_thawer ();
315 350
316 void get (attachable *obj, int oid); 351 void get (attachable *obj, int oid);
317 352
318 keyword get_kv (); // also parse value for later use 353 keyword get_kv (); // also parse value for later use
354 void skip_kv (keyword kw);
319 355
320 const char *get_str () { return last_value; } // may be 0 356 const char *get_str () { return last_value; } // may be 0
321 357
322 void get (shstr &sh) const; 358 void get (shstr &sh) const;
323 void get_ornull (shstr &sh) const { sh = last_value; } 359 void get_ornull (shstr &sh) const { sh = last_value; }
325 361
326 sint32 get_sint32 () const; 362 sint32 get_sint32 () const;
327 sint64 get_sint64 () const; 363 sint64 get_sint64 () const;
328 double get_double () const; 364 double get_double () const;
329 365
330 void get (float &v) { v = get_double (); } 366 void get (float &v) { v = get_double (); }
331 void get (double &v) { v = get_double (); } 367 void get (double &v) { v = get_double (); }
332 368
369 void get (bool &i) { i = get_sint32 (); }
333 void get (sint8 &i) { i = get_sint32 (); } 370 void get (sint8 &i) { i = get_sint32 (); }
334 void get (uint8 &i) { i = get_sint32 (); } 371 void get (uint8 &i) { i = get_sint32 (); }
335 void get (sint16 &i) { i = get_sint32 (); } 372 void get (sint16 &i) { i = get_sint32 (); }
336 void get (uint16 &i) { i = get_sint32 (); } 373 void get (uint16 &i) { i = get_sint32 (); }
337 void get (sint32 &i) { i = get_sint32 (); } 374 void get (sint32 &i) { i = get_sint32 (); }
340 void get (sint64 &i) { i = get_sint64 (); } 377 void get (sint64 &i) { i = get_sint64 (); }
341}; 378};
342 379
343char *fgets (char *s, int n, object_thawer &thawer); 380char *fgets (char *s, int n, object_thawer &thawer);
344 381
382//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
383
384struct coroapi {
385 static struct CoroAPI *GCoroAPI;
386
387 static int nready () { return CORO_NREADY; }
388 static int cede () { return CORO_CEDE ; }
389};
390
345struct watcher_base 391struct watcher_base
346{ 392{
347 static struct EventAPI *GEventAPI; 393 static struct EventAPI *GEventAPI;
348}; 394};
349 395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines