XS generado tiene en su cabecera
las declaraciones XSUB de las funciones de la librería:
lhp@nereida:~/projects/perl/src/XSUB/h2xsexample/Coord$ cat -n Coord.xs 1 #include "EXTERN.h" 2 #include "perl.h" 3 #include "XSUB.h" 4 5 #include "ppport.h" 6 7 #include <coord.h> 8 9 #include "const-c.inc" 10 11 MODULE = Coord PACKAGE = Coord 12 13 INCLUDE: const-xs.inc 14 15 polar 16 getpolar() 17 18 rectangular 19 getrectangular() 20 21 rectangular 22 pl2rc(p) 23 polar p 24 25 char * 26 polar2str(f, p) 27 const char * f 28 polar p 29 .. ................. resto de declaraciones
Después de las declaraciones siguen dos paquetes asociados con las declaraciones de
rectangular y rectangular *.
El paquete rectangular provee los métodos
new y _to_ptr:
39 MODULE = Coord PACKAGE = rectangular
40
41 rectangular *
42 _to_ptr(THIS)
43 rectangular THIS = NO_INIT
44 PROTOTYPE: $
45 CODE:
46 if (sv_derived_from(ST(0), "rectangular")) {
47 STRLEN len;
48 char *s = SvPV((SV*)SvRV(ST(0)), len);
49 if (len != sizeof(THIS))
50 croak("Size %d of packed data != expected %d",
51 len, sizeof(THIS));
52 RETVAL = (rectangular *)s;
53 }
54 else
55 croak("THIS is not of type rectangular");
56 OUTPUT:
57 RETVAL
58
59 rectangular
60 new(CLASS)
61 char *CLASS = NO_INIT
62 PROTOTYPE: $
63 CODE:
64 Zero((void*)&RETVAL, sizeof(RETVAL), char);
65 OUTPUT:
66 RETVAL
