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.14 by root, Tue Feb 7 23:29:55 2006 UTC vs.
Revision 1.15 by root, Wed Feb 8 03:46:15 2006 UTC

28#include <perl.h> 28#include <perl.h>
29#include <XSUB.h> 29#include <XSUB.h>
30 30
31#undef save_long // clashes with libproto.h 31#undef save_long // clashes with libproto.h
32 32
33#define PLUGIN_NAME "cfperl" 33#define PLUGIN_NAME "perl"
34#define PLUGIN_VERSION "cfperl 0.0" 34#define PLUGIN_VERSION "cfperl 0.0"
35 35
36#ifndef __CEXTRACT__ 36#ifndef __CEXTRACT__
37#include <plugin.h> 37#include <plugin.h>
38#endif 38#endif
62 object* activator; 62 object* activator;
63 object* third; 63 object* third;
64 char message[1024]; 64 char message[1024];
65 int fix; 65 int fix;
66 int event_code; 66 int event_code;
67 char options[1024]; 67 char extension[1024]; // name field, should invoke specific perl extension
68 char options[1024]; // slaying field of event_connectors
68 int returnvalue; 69 int returnvalue;
69} CFPContext; 70} CFPContext;
70 71
71//static int current_command = -999; 72//static int current_command = -999;
72 73
244} 245}
245 246
246///////////////////////////////////////////////////////////////////////////// 247/////////////////////////////////////////////////////////////////////////////
247 248
248void 249void
249inject_event (CFPContext *context) 250inject_event (const char *func, CFPContext *context)
250{ 251{
251 dSP; 252 dSP;
252 253
253 ENTER; 254 ENTER;
254 SAVETMPS; 255 SAVETMPS;
255 256
256 PUSHMARK (SP); 257 PUSHMARK (SP);
257
258 EXTEND (SP, 2);
259 //PUSHs (sv_2mortal (newSViv (type)));
260 258
261 HV *hv = newHV (); 259 HV *hv = newHV ();
262#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) 260#define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0)
263 hv_context (CFAPI_POBJECT, ,who); 261 hv_context (CFAPI_POBJECT, ,who);
264 hv_context (CFAPI_POBJECT, ,activator); 262 hv_context (CFAPI_POBJECT, ,activator);
265 hv_context (CFAPI_POBJECT, ,third); 263 hv_context (CFAPI_POBJECT, ,third);
266 hv_context (CFAPI_STRING , ,message); 264 hv_context (CFAPI_STRING , ,message);
267 hv_context (CFAPI_INT ,&,fix); 265 hv_context (CFAPI_INT ,&,fix);
268 hv_context (CFAPI_INT ,&,event_code); 266 hv_context (CFAPI_INT ,&,event_code);
269 hv_context (CFAPI_STRING , ,options); 267 hv_context (CFAPI_STRING , ,options);
268 hv_context (CFAPI_STRING , ,extension);
270 269
271 PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 270 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
272 271
273 PUTBACK; 272 PUTBACK;
274 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); 273 int count = call_pv (func, G_SCALAR | G_EVAL);
275 SPAGAIN; 274 SPAGAIN;
276 275
277 if (SvTRUE (ERRSV)) 276 if (SvTRUE (ERRSV))
278 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); 277 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
279 278
488 case EVENT_LOGOUT: 487 case EVENT_LOGOUT:
489 pl = va_arg (args, player *); 488 pl = va_arg (args, player *);
490 context.activator = pl->ob; 489 context.activator = pl->ob;
491 buf = va_arg (args, char *); 490 buf = va_arg (args, char *);
492 if (buf != 0) 491 if (buf != 0)
493 strcpy (context.message, buf); 492 strncpy (context.message, buf, sizeof (context.message));
494 break; 493 break;
495 494
496 case EVENT_SHOUT: 495 case EVENT_SHOUT:
497 case EVENT_MUZZLE: 496 case EVENT_MUZZLE:
498 case EVENT_KICK: 497 case EVENT_KICK:
499 context.activator = va_arg (args, object *); 498 context.activator = va_arg (args, object *);
500 buf = va_arg (args, char *); 499 buf = va_arg (args, char *);
501 if (buf != 0) 500 if (buf != 0)
502 strcpy (context.message, buf); 501 strncpy (context.message, buf, sizeof (context.message));
503 break; 502 break;
504 503
505 case EVENT_CLOCK: 504 case EVENT_CLOCK:
506 clean_obj_cache (); 505 clean_obj_cache ();
507 break; 506 break;
510 break; 509 break;
511 510
512 case EVENT_MAPRESET: 511 case EVENT_MAPRESET:
513 buf = va_arg (args, char *); 512 buf = va_arg (args, char *);
514 if (buf != 0) 513 if (buf != 0)
515 strcpy (context.message, buf); 514 strncpy (context.message, buf, sizeof (context.message));
516 break; 515 break;
517 } 516 }
518 517
519 va_end (args); 518 va_end (args);
520 519
527 clearSVptr (sv); 526 clearSVptr (sv);
528 SvREFCNT_dec (sv); 527 SvREFCNT_dec (sv);
529 } 528 }
530 } 529 }
531 else 530 else
532 inject_event (&context); 531 inject_event ("cf::inject_global_event", &context);
533 532
534 rv = context.returnvalue; 533 rv = context.returnvalue;
535 534
536 return &rv; 535 return &rv;
537} 536}
553 552
554 context.who = va_arg (args, object *); 553 context.who = va_arg (args, object *);
555 context.event_code = va_arg (args, int); 554 context.event_code = va_arg (args, int);
556 context.activator = va_arg (args, object *); 555 context.activator = va_arg (args, object *);
557 context.third = va_arg (args, object *); 556 context.third = va_arg (args, object *);
557
558 buf = va_arg (args, char *); 558 buf = va_arg (args, char *);
559
560 if (buf != 0) 559 if (buf != 0)
561 strcpy (context.message, buf); 560 strncpy (context.message, buf, sizeof (context.message));
562 561
563 context.fix = va_arg (args, int); 562 context.fix = va_arg (args, int);
563 strncpy (context.extension, va_arg (args, char *), sizeof (context.extension));
564 strcpy (context.options, va_arg (args, char *)); 564 strncpy (context.options, va_arg (args, char *), sizeof (context.options));
565 context.returnvalue = 0; 565 context.returnvalue = 0;
566 va_end (args); 566 va_end (args);
567 567
568 inject_event (&context); 568 inject_event ("cf::inject_event", &context);
569 569
570 rv = context.returnvalue; 570 rv = context.returnvalue;
571 return &rv; 571 return &rv;
572} 572}
573 573
1267void cf_fix_object (object *pl) 1267void cf_fix_object (object *pl)
1268 ALIAS: fix = 0 1268 ALIAS: fix = 0
1269 1269
1270object *cf_insert_ob_in_ob (object *ob, object *where) 1270object *cf_insert_ob_in_ob (object *ob, object *where)
1271 1271
1272void rangevector (object *ob, object *other, int flags = 0)
1273 PROTOTYPE: $$;$
1274 ALIAS:
1275 direction = 1
1276 distance = 2
1277 CODE:
1278{
1279 rv_vector rv;
1280 // get_rangevector uses these if the objects are not on the same map
1281 // which is not the same as "on_same_map".
1282 rv.distance_x = 32767;
1283 rv.distance_y = 32767;
1284 get_rangevector (ob, other, &rv, flags);
1285 EXTEND (SP, 5);
1286 if (!ix || ix == 2) PUSHs (newSVuv (rv.distance));
1287 if (!ix) PUSHs (newSViv (rv.distance_x));
1288 if (!ix) PUSHs (newSViv (rv.distance_y));
1289 if (!ix || ix == 1) PUSHs (newSViv (rv.direction));
1290 if (!ix) PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part));
1291}
1292
1293bool on_same_map_as (object *ob, object *other)
1294 CODE:
1295 RETVAL = on_same_map (ob, other);
1296 OUTPUT: RETVAL
1297
1272 1298
1273MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1299MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1274 1300
1275player *player (object *op) 1301player *player (object *op)
1276 CODE: 1302 CODE:
1307# nonstandard 1333# nonstandard
1308object *ob (player *pl) 1334object *ob (player *pl)
1309 CODE: 1335 CODE:
1310 RETVAL = pl->ob; 1336 RETVAL = pl->ob;
1311 OUTPUT: RETVAL 1337 OUTPUT: RETVAL
1338
1339player *first ()
1340 CODE:
1341 RETVAL = first_player;
1342 OUTPUT: RETVAL
1343
1344player *next (player *pl)
1345 CODE:
1346 RETVAL = pl->next;
1347 OUTPUT: RETVAL
1348
1349void
1350list ()
1351 PPCODE:
1352{
1353 player *pl;
1354 for (pl = first_player; pl; pl = pl->next)
1355 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl));
1356}
1312 1357
1313 1358
1314MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ 1359MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1315 1360
1316SV * 1361SV *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines