When using XS with C ++, the XS preprocessor inserts THIS , for example, methods and CLASS for static methods. A method called new is considered a static method. This allows you to use xsubs as instance methods / class methods by default: matrix->new and $m->getInnerMatrix() .
Your sample map uses the CLASS variable, which is not provided for instance methods. In your case, I would hard code the package name in the type map:
OUTPUT O_MATRIX sv_setref_pv( $arg, "matrix", (void*)$var );
A type map is also used when an argument of this type is not used as an invocant. For example. consider this xsub:
matrix* some_other_xsub(x) int x
There will not be a CLASS variable for the return value of matrix* .
Please note that lowercase names should only be used for pragma packages (e.g. strict or warnings ). Use CamelCase for your classes.
Your attempt to provide your own value for CLASS failed because SvPV_nolen() builds the link and does not get the reference type. That is, it is equivalent to "$m" , not ref $m . A more suitable alternative would be to use sv_ref() :
char* CLASS = SvPV_nolen(sv_ref(NULL, THIS, true));
The third parameter sv_ref() makes this function work as a Perl ref function, i.e. returns the name of the class if the scalar is blissful, and not just the base type of the link.
amon
source share