summaryrefslogtreecommitdiff
path: root/pod/perlxs.pod
diff options
context:
space:
mode:
authorRujith S. de Silva <desilva@netbox.com>1997-09-05 00:00:00 +0000
committerTim Bunce <Tim.Bunce@ig.co.uk>1997-09-05 00:00:00 +0000
commit1748e8dd6b8c191183a3274a47dc445791b196e8 (patch)
tree023ac02df0691c468c2f5681b249d895fa02fd29 /pod/perlxs.pod
parent96ee7dee3216b9d5ceca9d3e1807c0c8123e0b84 (diff)
downloadperl-1748e8dd6b8c191183a3274a47dc445791b196e8.tar.gz
xsubpp: document advanced dynamic typemap usage
Diffstat (limited to 'pod/perlxs.pod')
-rw-r--r--pod/perlxs.pod31
1 files changed, 31 insertions, 0 deletions
diff --git a/pod/perlxs.pod b/pod/perlxs.pod
index 13ad669531..6629af2dd5 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 *<tab>T_PTROBJ
+Here's a more complicated example: suppose that you wanted C<struct
+netconfig> to be blessed into the class C<Net::Config>. 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<T_PTROBJ_SPECIAL> that maps underscores to
+double-colons (::), and declare C<Net_Config> 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<RPC.xs>: Interface to some ONC+ RPC bind library functions.