From: Rujith S. de Silva Date: Fri, 5 Sep 1997 00:00:00 +0000 (+0000) Subject: xsubpp: document advanced dynamic typemap usage X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1748e8dd6b8c191183a3274a47dc445791b196e8;p=p5sagit%2Fp5-mst-13.2.git xsubpp: document advanced dynamic typemap usage --- diff --git a/pod/perlxs.pod b/pod/perlxs.pod index 13ad669..6629af2 100644 --- a/pod/perlxs.pod +++ b/pod/perlxs.pod @@ -1102,6 +1102,37 @@ that the C unary operator C<*> is considered to be a part of the C type name. TYPEMAP Netconfig *T_PTROBJ +Here's a more complicated example: suppose that you wanted C to be blessed into the class C. One way to do +this is to use underscores (_) to separate package names, as follows: + + typedef struct netconfig * Net_Config; + +And then provide a typemap entry C that maps underscores to +double-colons (::), and declare C to be of that type: + + + TYPEMAP + Net_Config T_PTROBJ_SPECIAL + + INPUT + T_PTROBJ_SPECIAL + if (sv_derived_from($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\")) { + IV tmp = SvIV((SV*)SvRV($arg)); + $var = ($type) tmp; + } + else + croak(\"$var is not of type ${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\") + + OUTPUT + T_PTROBJ_SPECIAL + sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/_/::/g;\$ntt}\", + (void*)$var); + +The INPUT and OUTPUT sections substitute underscores for double-colons +on the fly, giving the desired effect. This example demonstrates some +of the power and versatility of the typemap facility. + =head1 EXAMPLES File C: Interface to some ONC+ RPC bind library functions.