So INPUT typemap kicks in when you pass your XSUB an appropriate
argument. 'OBJECT *obj' is such an argument and now Perl will convert
the SV* it receives into a pointer to OBJECT according to the
INPUT/O_OBJECT typemap. When returning 'OBJECT*', OUTPUT/O_OBJECT turns
a C++ object into a SV*.

When calling a Perl-callback however, you have to do this conversion
manually as I showed further above. You just copy the pointer (casted to
(void*) into an SV using sv_setref_pv(), at the same time blessing the
scalar variable into the appropriate package that should handle objects
of this type. Since your function read() operates on the C++ object,
bless it into the package where this method is defined. Use the INPUT
there and your Perl object is turned into a C++ again.
> I've read perlgut, perlapi, perlxs, perlxstut, cookbookA and
> cookbookB, and googled all day and I'm still no closer to a solution.

I was just about to recommend cookbookA and cookbookB, but you have
already read that. It's not exactly full of verbose explanations, it
just gives a few examples. Do they make more sense now? You could try to
re-read perlxs.pod, section "Using XS with C++".

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!