… | |
… | |
294 | |
294 | |
295 | attach = src.attach; |
295 | attach = src.attach; |
296 | return *this; |
296 | return *this; |
297 | } |
297 | } |
298 | |
298 | |
|
|
299 | #if 0 |
299 | template<typename T> |
300 | template<typename T> |
300 | static bool |
301 | static bool |
301 | find_backref (void *ptr, T *obj) |
302 | find_backref (void *ptr, T *obj) |
302 | { |
303 | { |
303 | char *s = (char *)obj; |
304 | char *s = (char *)obj; |
… | |
… | |
311 | |
312 | |
312 | return false; |
313 | return false; |
313 | } |
314 | } |
314 | |
315 | |
315 | // for debugging, find "live" objects containing this ptr |
316 | // for debugging, find "live" objects containing this ptr |
316 | void |
317 | static void |
317 | find_backref (void *ptr) |
318 | find_backref (void *ptr) |
318 | { |
319 | { |
319 | for_all_objects (op) |
320 | for_all_objects (op) |
320 | if (find_backref (ptr, op)) |
321 | if (find_backref (ptr, op)) |
321 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
322 | fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
… | |
… | |
326 | |
327 | |
327 | for_all_clients (ns) |
328 | for_all_clients (ns) |
328 | if (find_backref (ptr, ns)) |
329 | if (find_backref (ptr, ns)) |
329 | fprintf (stderr, "C %p\n", ns); |
330 | fprintf (stderr, "C %p\n", ns); |
330 | } |
331 | } |
|
|
332 | #endif |
331 | |
333 | |
332 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
334 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
333 | |
335 | |
334 | static SV * |
336 | static SV * |
335 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
337 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
… | |
… | |
423 | return SvPTR (sv, klass); |
425 | return SvPTR (sv, klass); |
424 | else |
426 | else |
425 | return 0; |
427 | return 0; |
426 | } |
428 | } |
427 | |
429 | |
428 | inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
430 | static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
429 | inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
431 | static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
430 | inline SV *to_sv (bool v) { return newSViv (v); } |
432 | static inline SV *to_sv (bool v) { return newSViv (v); } |
431 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
433 | static inline SV *to_sv ( signed char v) { return newSViv (v); } |
432 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
434 | static inline SV *to_sv (unsigned char v) { return newSViv (v); } |
433 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
435 | static inline SV *to_sv ( signed short v) { return newSViv (v); } |
434 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
436 | static inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
435 | inline SV *to_sv ( signed int v) { return newSViv (v); } |
437 | static inline SV *to_sv ( signed int v) { return newSViv (v); } |
436 | inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
438 | static inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
437 | inline SV *to_sv ( signed long v) { return newSViv (v); } |
439 | static inline SV *to_sv ( signed long v) { return newSViv (v); } |
438 | inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
440 | static inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
439 | inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
441 | static inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
440 | inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
442 | static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
441 | inline SV *to_sv (float v) { return newSVnv (v); } |
443 | static inline SV *to_sv (float v) { return newSVnv (v); } |
442 | inline SV *to_sv (double v) { return newSVnv (v); } |
444 | static inline SV *to_sv (double v) { return newSVnv (v); } |
443 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
445 | static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
444 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
446 | static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
445 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
447 | static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
446 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
448 | static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
447 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
449 | static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
448 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
450 | static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
449 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
451 | static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
450 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
452 | static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
451 | inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
453 | static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
452 | |
454 | |
453 | inline SV *to_sv (object & v) { return to_sv (&v); } |
455 | static inline SV *to_sv (object & v) { return to_sv (&v); } |
454 | inline SV *to_sv (living & v) { return to_sv (&v); } |
456 | static inline SV *to_sv (living & v) { return to_sv (&v); } |
455 | |
457 | |
456 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
458 | static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
457 | inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
459 | static inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
458 | |
460 | |
459 | inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } |
461 | static inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } |
460 | |
462 | |
461 | inline SV *to_sv (dynbuf * v) |
463 | static inline SV *to_sv (dynbuf * v) |
462 | { |
464 | { |
463 | SV *sv = newSV (0); |
465 | SV *sv = newSV (0); |
464 | |
466 | |
465 | sv_upgrade (sv, SVt_PV); |
467 | sv_upgrade (sv, SVt_PV); |
466 | SvGROW (sv, v->size () + 1); |
468 | SvGROW (sv, v->size () + 1); |
… | |
… | |
470 | *SvEND (sv) = 0; |
472 | *SvEND (sv) = 0; |
471 | |
473 | |
472 | return sv; |
474 | return sv; |
473 | } |
475 | } |
474 | |
476 | |
475 | inline SV *to_sv (dynbuf_text * v) |
477 | static inline SV *to_sv (dynbuf_text * v) |
476 | { |
478 | { |
477 | SV *sv = to_sv (static_cast<dynbuf *> (v)); |
479 | SV *sv = to_sv (static_cast<dynbuf *> (v)); |
478 | SvUTF8_on (sv); |
480 | SvUTF8_on (sv); |
479 | return sv; |
481 | return sv; |
480 | } |
482 | } |
481 | |
483 | |
482 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
484 | static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } |
483 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
485 | static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
484 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
486 | static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
485 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
487 | static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
486 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
488 | static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
487 | inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
489 | static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
488 | inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
490 | static inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
489 | inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
491 | static inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
490 | inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
492 | static inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
491 | inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
493 | static inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
492 | inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
494 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
493 | inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
495 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
494 | inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
496 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
495 | inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
497 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
496 | inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
498 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
497 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
499 | static inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
498 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
500 | static inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
499 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
501 | static inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
500 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
502 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
501 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
503 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
502 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
504 | static inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
503 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
505 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
504 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
506 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
505 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
507 | static inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
506 | inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } |
508 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } |
507 | inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
509 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
508 | inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
510 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
509 | |
511 | |
510 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
512 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
511 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
513 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
512 | |
514 | |
513 | template<class T> |
515 | template<class T> |
514 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
516 | static inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
515 | |
517 | |
516 | template<int N> |
518 | template<int N> |
517 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
519 | static inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
518 | |
520 | |
519 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
521 | static inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
520 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
522 | static inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
521 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
523 | static inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
522 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
524 | static inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
523 | |
525 | |
524 | inline void sv_to (SV *sv, std::string &v) |
526 | static inline void sv_to (SV *sv, std::string &v) |
525 | { |
527 | { |
526 | STRLEN len; |
528 | STRLEN len; |
527 | char *data = SvPVbyte (sv, len); |
529 | char *data = SvPVbyte (sv, len); |
528 | v.assign (data, len); |
530 | v.assign (data, len); |
529 | } |
531 | } |
530 | |
532 | |
531 | inline void sv_to (SV *sv, UUID &v) |
533 | static inline void sv_to (SV *sv, UUID &v) |
532 | { |
534 | { |
533 | if (!v.parse (SvPV_nolen (sv))) |
535 | if (!v.parse (SvPV_nolen (sv))) |
534 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
536 | croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
535 | } |
537 | } |
536 | |
538 | |
537 | inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
539 | static inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
538 | |
540 | |
539 | static SV * |
541 | static SV * |
540 | newSVdt_va (va_list &ap, data_type type) |
542 | newSVdt_va (va_list &ap, data_type type) |
541 | { |
543 | { |
542 | SV *sv; |
544 | SV *sv; |
… | |
… | |
642 | var = 0; |
644 | var = 0; |
643 | } |
645 | } |
644 | |
646 | |
645 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
647 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
646 | |
648 | |
647 | SV * |
649 | static SV * |
648 | registry (attachable *ext) |
650 | registry (attachable *ext) |
649 | { |
651 | { |
650 | if (!ext->cb) |
652 | if (!ext->cb) |
651 | ext->cb = newAV (); |
653 | ext->cb = newAV (); |
652 | |
654 | |
… | |
… | |
936 | CALL_END; |
938 | CALL_END; |
937 | |
939 | |
938 | return count; |
940 | return count; |
939 | } |
941 | } |
940 | |
942 | |
941 | SV * |
943 | static SV * |
942 | cfperl_result (int idx) |
944 | cfperl_result (int idx) |
943 | { |
945 | { |
944 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
946 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
945 | if (!av) |
947 | if (!av) |
946 | return &PL_sv_undef; |
948 | return &PL_sv_undef; |