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> |
… | |
… | |
99 | void cfperl_main (); |
95 | void cfperl_main (); |
100 | void cfperl_tick (); |
96 | void cfperl_tick (); |
101 | void cfperl_emergency_save (); |
97 | void cfperl_emergency_save (); |
102 | void cfperl_cleanup (int make_core); |
98 | void cfperl_cleanup (int make_core); |
103 | void cfperl_make_book (object *book, int level); |
99 | void cfperl_make_book (object *book, int level); |
104 | void cfperl_send_msg (client *ns, int color, const char *type, const char *msg); |
100 | void cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg); |
105 | int cfperl_can_merge (object *ob1, object *ob2); |
101 | int cfperl_can_merge (object *ob1, object *ob2); |
106 | void cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator = 0); |
102 | void cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator = 0); |
107 | |
103 | |
108 | bool is_match_expr (const char *expr); |
104 | bool is_match_expr (const_utf8_string expr); |
109 | // applies the match expression and returns true if it matches |
105 | // applies the match expression and returns true if it matches |
110 | bool match (const char *expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); |
106 | bool match (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); |
111 | // same as above, but returns the first object found, or 0 |
107 | // same as above, but returns the first object found, or 0 |
112 | object *match_one (const char *expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); |
108 | object *match_one (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0); |
113 | |
109 | |
114 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
115 | |
111 | |
116 | #if IVSIZE >= 8 |
112 | #if IVSIZE >= 8 |
117 | typedef IV val64; |
113 | typedef IV val64; |
… | |
… | |
240 | : attachable_flags (0), self (0), cb (0), attach (src.attach) |
236 | : attachable_flags (0), self (0), cb (0), attach (src.attach) |
241 | { |
237 | { |
242 | } |
238 | } |
243 | |
239 | |
244 | // set a custom key to the given value, or delete it if value = 0 |
240 | // set a custom key to the given value, or delete it if value = 0 |
245 | void set_key (const char *key, const char *value = 0, bool is_utf8 = 0); |
241 | void set_key (const_utf8_string key, const_utf8_string value = 0, bool is_utf8 = 0); |
246 | |
242 | |
247 | void set_key_text (const char *key, const char *value = 0) |
243 | void set_key_text (const_utf8_string key, const_utf8_string value = 0) |
248 | { |
244 | { |
249 | set_key (key, value, 1); |
245 | set_key (key, value, 1); |
250 | } |
246 | } |
251 | |
247 | |
252 | void set_key_data (const char *key, const char *value = 0) |
248 | void set_key_data (const_utf8_string key, const_utf8_string value = 0) |
253 | { |
249 | { |
254 | set_key (key, value, 0); |
250 | set_key (key, value, 0); |
255 | } |
251 | } |
256 | |
252 | |
257 | attachable &operator =(const attachable &src); |
253 | attachable &operator =(const attachable &src); |
258 | |
254 | |
259 | // used to _quickly_ device wether to shortcut the evaluation |
255 | // used to _quickly_ decide wether to shortcut the evaluation |
260 | bool should_invoke (event_type event) |
256 | bool should_invoke (event_type event) |
261 | { |
257 | { |
262 | return ev_want_event [event] || cb; |
258 | return ev_want_event [event] || cb; |
263 | } |
259 | } |
264 | |
260 | |
… | |
… | |
342 | memcpy (p, k.s, k.l); p += k.l; *p++ = ' '; |
338 | memcpy (p, k.s, k.l); p += k.l; *p++ = ' '; |
343 | memcpy (p, v.s, v.l); p += v.l; *p++ = '\n'; |
339 | memcpy (p, v.s, v.l); p += v.l; *p++ = '\n'; |
344 | alloc (p); |
340 | alloc (p); |
345 | } |
341 | } |
346 | |
342 | |
347 | void put (const keyword_string k, const char *v) |
343 | void put (const keyword_string k, const_utf8_string v) |
348 | { |
344 | { |
349 | if (expect_true (v)) |
345 | if (expect_true (v)) |
350 | put (k, keyword_string (v, strlen (v))); |
346 | put (k, keyword_string (v, strlen (v))); |
351 | else |
347 | else |
352 | put (k); |
348 | put (k); |
… | |
… | |
419 | { |
415 | { |
420 | put (k, (T *)v); |
416 | put (k, (T *)v); |
421 | } |
417 | } |
422 | |
418 | |
423 | MTH bool save (const_octet_string path); |
419 | MTH bool save (const_octet_string path); |
424 | char *as_string (); // like strdup |
420 | utf8_string as_string (); // like strdup |
425 | |
421 | |
426 | operator bool () { return !!av; } |
422 | operator bool () { return !!av; } |
427 | }; |
423 | }; |
428 | |
424 | |
429 | INTERFACE_CLASS(object_thawer) |
425 | INTERFACE_CLASS(object_thawer) |
… | |
… | |
439 | const char *value_nn; // the value, or the empty string if no value |
435 | const char *value_nn; // the value, or the empty string if no value |
440 | const char *name; |
436 | const char *name; |
441 | |
437 | |
442 | operator bool () const { return !!text; } |
438 | operator bool () const { return !!text; } |
443 | |
439 | |
444 | object_thawer (const char *path = 0); |
440 | object_thawer (const_utf8_string path = 0); |
445 | object_thawer (const char *data, AV *perlav); |
441 | object_thawer (const_utf8_string data, AV *perlav); |
446 | ~object_thawer (); |
442 | ~object_thawer (); |
447 | |
443 | |
448 | void get (attachable *obj, int oid); |
444 | void get (attachable *obj, int oid); |
449 | |
445 | |
450 | // parse next line |
446 | // parse next line |
… | |
… | |
453 | // multiline-fields, skips till the corresponding end-kw |
449 | // multiline-fields, skips till the corresponding end-kw |
454 | MTH void skip (); |
450 | MTH void skip (); |
455 | MTH void skip_block (); // skips till and over KW_end |
451 | MTH void skip_block (); // skips till and over KW_end |
456 | |
452 | |
457 | bool has_value () { return value; } |
453 | bool has_value () { return value; } |
458 | const char *get_str () { return value_nn; } // empty string when missing |
454 | const_utf8_string get_str () { return value_nn; } // empty string when missing |
459 | void get_ml (keyword kend, shstr &sh); |
455 | void get_ml (keyword kend, shstr &sh); |
460 | |
456 | |
461 | void get_ornull (shstr &sh) const { sh = value; } |
457 | void get_ornull (shstr &sh) const { sh = value; } |
462 | void get (shstr &sh) const { sh = value; } // might want to check for non-null here |
458 | void get (shstr &sh) const { sh = value; } // might want to check for non-null here |
463 | |
459 | |
… | |
… | |
477 | void get (sint32 &i) { i = get_sint32 (); } |
473 | void get (sint32 &i) { i = get_sint32 (); } |
478 | |
474 | |
479 | void get (uint32 &i) { i = get_sint64 (); } |
475 | void get (uint32 &i) { i = get_sint64 (); } |
480 | void get (sint64 &i) { i = get_sint64 (); } |
476 | void get (sint64 &i) { i = get_sint64 (); } |
481 | |
477 | |
482 | MTH void parse_warn (const char *msg); |
478 | MTH void parse_warn (const_utf8_string msg); |
483 | MTH bool parse_error (const char *type = 0, const char *name = 0, bool skip = true); |
479 | MTH bool parse_error (const_utf8_string type = 0, const_utf8_string name = 0, bool skip = true); |
484 | |
480 | |
485 | struct delayed_ref { |
481 | struct delayed_ref { |
486 | attachable *op; |
482 | attachable *op; |
487 | object_ptr *ptr; |
483 | object_ptr *ptr; |
488 | const char *ref; |
484 | const_utf8_string ref; |
489 | }; |
485 | }; |
490 | std::vector<delayed_ref> delrefs; |
486 | std::vector<delayed_ref> delrefs; |
491 | |
487 | |
492 | void delayed_deref (attachable *op, object_ptr &ptr, const char *ref); |
488 | void delayed_deref (attachable *op, object_ptr &ptr, const_utf8_string ref); |
493 | MTH void resolve_delayed_derefs (bool deref = true); |
489 | MTH void resolve_delayed_derefs (bool deref = true); |
494 | }; |
490 | }; |
495 | |
491 | |
496 | //TODO: remove |
492 | //TODO: remove |
497 | char *fgets (char *s, int n, object_thawer &thawer); |
493 | char *fgets (char *s, int n, object_thawer &thawer); |