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

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.43 by root, Fri Mar 31 19:47:55 2006 UTC vs.
Revision 1.45 by root, Fri Mar 31 20:59:17 2006 UTC

65typedef struct 65typedef struct
66{ 66{
67 object* who; 67 object* who;
68 object* activator; 68 object* activator;
69 object* third; 69 object* third;
70 object* event;
70 mapstruct* map; 71 mapstruct* map;
71 char message[1024]; 72 char message[1024];
72 int fix; // seems to be python-only, and should not be part of the API 73 int fix; // seems to be python-only, and should not be part of the API
73 int event_code; 74 int event_code;
74 char extension[1024]; // name field, should invoke specific perl extension 75 char extension[1024]; // name field, should invoke specific perl extension
291 va_end (args); 292 va_end (args);
292 293
293 return sv; 294 return sv;
294} 295}
295 296
296/////////////////////////////////////////////////////////////////////////////
297
298void
299inject_event (const char *func, CFPContext *context)
300{
301 dSP;
302
303 ENTER;
304 SAVETMPS;
305
306 PUSHMARK (SP);
307
308 EXTEND (SP, 10);
309
310 HV *hv = newHV ();
311#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
312 hv_context (CFAPI_POBJECT, ,who);
313 hv_context (CFAPI_POBJECT, ,activator);
314 hv_context (CFAPI_POBJECT, ,third);
315 hv_context (CFAPI_PMAP, ,map);
316 hv_context (CFAPI_STRING , ,message);
317 hv_context (CFAPI_INT ,&,fix);
318 hv_context (CFAPI_INT ,&,event_code);
319 hv_context (CFAPI_STRING , ,options);
320 hv_context (CFAPI_STRING , ,extension);
321
322 PUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
323
324 PUTBACK;
325 int count = call_pv (func, G_SCALAR | G_EVAL);
326 SPAGAIN;
327
328 if (SvTRUE (ERRSV))
329 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
330
331 context->returnvalue = count > 0 ? POPi : 0;
332
333 PUTBACK;
334 FREETMPS;
335 LEAVE;
336}
337
338///////////////////////////////////////////////////////////////////////////// 297/////////////////////////////////////////////////////////////////////////////
339 298
340int 299int
341initPlugin (const char *iversion, f_plug_api gethooksptr) 300initPlugin (const char *iversion, f_plug_api gethooksptr)
342{ 301{
617{ 576{
618 static int rv = 0; 577 static int rv = 0;
619 va_list args; 578 va_list args;
620 char *buf; 579 char *buf;
621 CFPContext context; 580 CFPContext context;
622 object *eob;
623 581
624 if (!perl) 582 if (!perl)
625 return; 583 return;
626 584
627 memset (&context, 0, sizeof (context)); 585 memset (&context, 0, sizeof (context));
638 strncpy (context.message, buf, sizeof (context.message)); 596 strncpy (context.message, buf, sizeof (context.message));
639 597
640 context.fix = va_arg (args, int); 598 context.fix = va_arg (args, int);
641 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); 599 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
642 strncpy (context.options, va_arg (args, char *), sizeof (context.options)); 600 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
643 eob = va_arg (args, object *); 601 context.event = va_arg (args, object *);
644 context.returnvalue = 0;
645 va_end (args); 602 va_end (args);
646 603
647 inject_event ("cf::inject_event", &context); 604 {
605 dSP;
606
607 ENTER;
608 SAVETMPS;
609
610 PUSHMARK (SP);
611
612 EXTEND (SP, 10);
613
614 HV *hv = newHV ();
615#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context.expr), 0)
616 hv_context (CFAPI_POBJECT, ,who);
617 hv_context (CFAPI_POBJECT, ,activator);
618 hv_context (CFAPI_POBJECT, ,third);
619 hv_context (CFAPI_POBJECT, ,event);
620 hv_context (CFAPI_PMAP, ,map);
621 hv_context (CFAPI_STRING , ,message);
622 hv_context (CFAPI_INT ,&,fix);
623 hv_context (CFAPI_INT ,&,event_code);
624 hv_context (CFAPI_STRING , ,options);
625 hv_context (CFAPI_STRING , ,extension);
626
627 PUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
628
629 PUTBACK;
630 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
631 SPAGAIN;
632
633 if (SvTRUE (ERRSV))
634 LOG (llevError, "event '%d' callback evaluation error: %s", context.event_code, SvPV_nolen (ERRSV));
635
636 context.returnvalue = count > 0 ? POPi : 0;
637
638 PUTBACK;
639 FREETMPS;
640 LEAVE;
641 }
648 642
649 rv = context.returnvalue; 643 rv = context.returnvalue;
650 return &rv; 644 return &rv;
651} 645}
652 646

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines