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

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.277 by root, Sat Apr 19 21:10:29 2008 UTC vs.
Revision 1.290 by root, Sat May 17 14:57:23 2008 UTC

21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include "autoconf.h" 24#include "autoconf.h"
25 25
26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5"
28
29#if HAVE_EXECINFO_H 26#if HAVE_EXECINFO_H
30# include <execinfo.h> 27# include <execinfo.h>
31#endif 28#endif
32 29
33#include <cstdarg> 30#include <cstdarg>
43# include <sys/mman.h> 40# include <sys/mman.h>
44#endif 41#endif
45 42
46#if HAVE_MALLOC_H 43#if HAVE_MALLOC_H
47# include <malloc.h> 44# include <malloc.h>
45#endif
46
47#if !__GLIBC__
48# define malloc_trim(pad) -1
48#endif 49#endif
49 50
50#include <EXTERN.h> 51#include <EXTERN.h>
51#include <perl.h> 52#include <perl.h>
52#include <XSUB.h> 53#include <XSUB.h>
940 CALL_CALL ("ext::books::make_book", G_VOID); 941 CALL_CALL ("ext::books::make_book", G_VOID);
941 CALL_END; 942 CALL_END;
942} 943}
943 944
944void 945void
946cfperl_expand_cfpod (player *pl, std::string &msg)
947{
948 CALL_BEGIN (2);
949 CALL_ARG (pl);
950 CALL_ARG_SV (newSVpvn_utf8 (msg.data (), msg.size ()));
951 CALL_CALL ("cf::player::expand_cfpod", G_SCALAR);
952
953 if (count)
954 {
955 STRLEN len;
956 char *data = SvPVutf8 (TOPs, len);
957 msg.assign (data, len);
958 }
959
960 CALL_END;
961}
962
963void
945cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 964cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
946{ 965{
947 CALL_BEGIN (4); 966 CALL_BEGIN (4);
948 CALL_ARG (ns); 967 CALL_ARG (ns);
949 CALL_ARG (type); 968 CALL_ARG (type);
973{ 992{
974 CALL_BEGIN (1); 993 CALL_BEGIN (1);
975 CALL_ARG (name); 994 CALL_ARG (name);
976 CALL_CALL ("cf::player::find", G_SCALAR); 995 CALL_CALL ("cf::player::find", G_SCALAR);
977 996
978 player *retval; 997 player *retval = 0;
979
980 if (count)
981 sv_to (POPs, retval); 998 if (count) sv_to (POPs, retval);
982 else 999
983 retval = 0; 1000 CALL_END;
1001
1002 return retval;
1003}
1004
1005maptile *
1006find_style (const char *dirname, const char *stylename, int difficulty)
1007{
1008 CALL_BEGIN (3);
1009 CALL_ARG (dirname);
1010 CALL_ARG (stylename);
1011 CALL_ARG (difficulty);
1012 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1013
1014 maptile *retval = 0;
1015 if (count) sv_to (POPs, retval);
984 1016
985 CALL_END; 1017 CALL_END;
986 1018
987 return retval; 1019 return retval;
988} 1020}
993 CALL_BEGIN (2); 1025 CALL_BEGIN (2);
994 CALL_ARG (path); 1026 CALL_ARG (path);
995 CALL_ARG (origin); 1027 CALL_ARG (origin);
996 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1028 CALL_CALL ("cf::map::find_sync", G_SCALAR);
997 1029
998 maptile *retval; 1030 maptile *retval = 0;
999
1000 if (count)
1001 sv_to (POPs, retval); 1031 if (count) sv_to (POPs, retval);
1002 else
1003 retval = 0;
1004 1032
1005 CALL_END; 1033 CALL_END;
1006 1034
1007 return retval; 1035 return retval;
1008} 1036}
1014 CALL_ARG (path); 1042 CALL_ARG (path);
1015 CALL_ARG (origin); 1043 CALL_ARG (origin);
1016 CALL_ARG (load); 1044 CALL_ARG (load);
1017 CALL_CALL ("cf::map::find_async", G_SCALAR); 1045 CALL_CALL ("cf::map::find_async", G_SCALAR);
1018 1046
1019 maptile *retval; 1047 maptile *retval = 0;
1020
1021 if (count)
1022 sv_to (POPs, retval); 1048 if (count) sv_to (POPs, retval);
1023 else
1024 retval = 0;
1025 1049
1026 CALL_END; 1050 CALL_END;
1027 1051
1028 return retval; 1052 return retval;
1029} 1053}
1054 1078
1055 CALL_BEGIN (2); 1079 CALL_BEGIN (2);
1056 CALL_ARG (this); 1080 CALL_ARG (this);
1057 CALL_ARG (exit); 1081 CALL_ARG (exit);
1058 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1082 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1083 CALL_END;
1084}
1085
1086void
1087object::player_goto (const char *path, int x, int y)
1088{
1089 if (type != PLAYER)
1090 return;
1091
1092 CALL_BEGIN (4);
1093 CALL_ARG (this);
1094 CALL_ARG (path);
1095 CALL_ARG (x);
1096 CALL_ARG (y);
1097 CALL_CALL ("cf::object::player::goto", G_VOID);
1059 CALL_END; 1098 CALL_END;
1060} 1099}
1061 1100
1062const char * 1101const char *
1063object::ref () const 1102object::ref () const
1428 1467
1429 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1468 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1430 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1469 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1431 1470
1432 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1471 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1433 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1472 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_MINIMAL)
1434 const_iv (GT_MINIMAL)
1435 1473
1436 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND) 1474 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1437 const_iv (FT_RSRC) const_iv (FT_NUM) 1475 const_iv (FT_RSRC) const_iv (FT_NUM)
1438 }; 1476 };
1439 1477
1570NV floor (NV x) 1608NV floor (NV x)
1571 1609
1572NV ceil (NV x) 1610NV ceil (NV x)
1573 1611
1574NV rndm (...) 1612NV rndm (...)
1613 ALIAS:
1614 rmg_rndm = 1
1575 CODE: 1615 CODE:
1616{
1617 rand_gen &gen = ix ? rmg_rndm : rndm;
1576 switch (items) 1618 switch (items)
1577 { 1619 {
1578 case 0: RETVAL = rndm (); break; 1620 case 0: RETVAL = gen (); break;
1579 case 1: RETVAL = rndm (SvUV (ST (0))); break; 1621 case 1: RETVAL = gen (SvUV (ST (0))); break;
1580 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; 1622 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1581 default: croak ("cf::rndm requires none, one or two parameters."); break; 1623 default: croak ("cf::rndm requires none, one or two parameters."); break;
1582 } 1624 }
1625}
1583 OUTPUT: 1626 OUTPUT:
1584 RETVAL 1627 RETVAL
1585 1628
1586NV clamp (NV value, NV min_value, NV max_value) 1629NV clamp (NV value, NV min_value, NV max_value)
1587 CODE: 1630 CODE:
1612octet_string path_combine (octet_string base, octet_string path) 1655octet_string path_combine (octet_string base, octet_string path)
1613 PROTOTYPE: $$ 1656 PROTOTYPE: $$
1614 1657
1615octet_string path_combine_and_normalize (octet_string base, octet_string path) 1658octet_string path_combine_and_normalize (octet_string base, octet_string path)
1616 PROTOTYPE: $$ 1659 PROTOTYPE: $$
1617
1618void
1619mallinfo ()
1620 PPCODE:
1621{
1622#if __GLIBC__
1623 struct mallinfo mai = mallinfo ();
1624 EXTEND (SP, 10*2);
1625 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1626 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1627 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1628 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1629 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1630 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1631 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1632 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1633 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1634 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1635#endif
1636 EXTEND (SP, 2*2);
1637 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1638 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1639}
1640 1660
1641void 1661void
1642sub_generation_inc () 1662sub_generation_inc ()
1643 CODE: 1663 CODE:
1644 PL_sub_generation++; 1664 PL_sub_generation++;
1681 1701
1682#if _POSIX_MEMLOCK 1702#if _POSIX_MEMLOCK
1683 1703
1684int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1704int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1685 INIT: 1705 INIT:
1686#ifdef __linux 1706#if __GLIBC__
1687 mallopt (M_PERTURB, 0xaa); // bug-workaround for linux glibc+mlockall+calloc 1707 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1688#endif 1708#endif
1689 1709
1690int munlockall () 1710int munlockall ()
1691 1711
1692#endif 1712#endif
1713
1714int
1715malloc_trim (IV pad = 0)
1716
1717void
1718mallinfo ()
1719 PPCODE:
1720{
1721#if __GLIBC__
1722 struct mallinfo mai = mallinfo ();
1723 EXTEND (SP, 10*2);
1724 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1725 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1726 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1727 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1728 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1729 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1730 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1731 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1732 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1733 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1734#endif
1735 EXTEND (SP, 2*2);
1736 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1737 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1738 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1739}
1693 1740
1694int find_animation (utf8_string text) 1741int find_animation (utf8_string text)
1695 PROTOTYPE: $ 1742 PROTOTYPE: $
1696 1743
1697int random_roll (int min, int max, object *op, int goodbad); 1744int random_roll (int min, int max, object *op, int goodbad);
1778 EXTEND (SP, NUM_COINS); 1825 EXTEND (SP, NUM_COINS);
1779 for (int i = 0; i < NUM_COINS; ++i) 1826 for (int i = 0; i < NUM_COINS; ++i)
1780 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i])))); 1827 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i]))));
1781 1828
1782bool 1829bool
1783load_resource_file (octet_string filename) 1830load_resource_file_ (octet_string filename)
1831
1832void
1833fix_weight ()
1784 1834
1785MODULE = cf PACKAGE = cf::attachable 1835MODULE = cf PACKAGE = cf::attachable
1786 1836
1787int 1837int
1788valid (SV *obj) 1838valid (SV *obj)
1852object *actives (U32 index) 1902object *actives (U32 index)
1853 CODE: 1903 CODE:
1854 RETVAL = index < actives.size () ? actives [index] : 0; 1904 RETVAL = index < actives.size () ? actives [index] : 0;
1855 OUTPUT: RETVAL 1905 OUTPUT: RETVAL
1856 1906
1907int mortals_size ()
1908 CODE:
1909 RETVAL = attachable::mortals.size ();
1910 OUTPUT: RETVAL
1911
1857const char *slot_use_name (U32 slot) 1912const char *slot_use_name (U32 slot)
1858 ALIAS: 1913 ALIAS:
1859 slot_nonuse_name = 1 1914 slot_nonuse_name = 1
1860 CODE: 1915 CODE:
1861{ 1916{
1939void apply_below (object *op) 1994void apply_below (object *op)
1940 CODE: 1995 CODE:
1941 player_apply_below (op); 1996 player_apply_below (op);
1942 1997
1943int cast_heal (object *op, object *caster, object *spell, int dir = 0) 1998int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1944
1945#//TODO
1946object *clone_ (object *op, int recursive = 0)
1947 CODE:
1948 if (recursive)
1949 RETVAL = object_create_clone (op);
1950 else
1951 {
1952 RETVAL = object::create ();
1953 op->copy_to (RETVAL);
1954 }
1955 OUTPUT: RETVAL
1956 1999
1957int pay_item (object *op, object *buyer) 2000int pay_item (object *op, object *buyer)
1958 CODE: 2001 CODE:
1959 RETVAL = pay_for_item (op, buyer); 2002 RETVAL = pay_for_item (op, buyer);
1960 OUTPUT: RETVAL 2003 OUTPUT: RETVAL
2038 CODE: 2081 CODE:
2039{ 2082{
2040 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2083 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2041} 2084}
2042 2085
2043const_utf8_string get_ob_key_value (object *op, utf8_string key) 2086shstr
2087object::kv_get (shstr key)
2044 2088
2045bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2089void
2090object::kv_del (shstr key)
2091
2092void
2093object::kv_set (shstr key, shstr value)
2046 2094
2047object *get_nearest_player (object *ob) 2095object *get_nearest_player (object *ob)
2048 ALIAS: nearest_player = 0 2096 ALIAS: nearest_player = 0
2049 PREINIT: 2097 PREINIT:
2050 extern object *get_nearest_player (object *); 2098 extern object *get_nearest_player (object *);
2071const_utf8_string 2119const_utf8_string
2072base_name (object *op, int plural = op->nrof > 1) 2120base_name (object *op, int plural = op->nrof > 1)
2073 CODE: 2121 CODE:
2074 RETVAL = query_base_name (op, plural); 2122 RETVAL = query_base_name (op, plural);
2075 OUTPUT: RETVAL 2123 OUTPUT: RETVAL
2076
2077object *decrease_ob_nr (object *op, unsigned long i)
2078 2124
2079# return the tail of an object, excluding itself 2125# return the tail of an object, excluding itself
2080void 2126void
2081tail (object *op) 2127tail (object *op)
2082 PPCODE: 2128 PPCODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines