Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How to use C++ in perl WITH OUT INLINE

by llancet (Friar)
on Jun 25, 2011 at 02:44 UTC ( [id://911352]=perlquestion: print w/replies, xml ) Need Help??

llancet has asked for the wisdom of the Perl Monks concerning the following question:

I guess someone will tell me Inline::CPP, but for some reason I'm not going to use it. I've also read the code of Inline::CPP, but failed to understand it.

I know perl has XS to work with C functions. However, how to use XS with the OO features in C++? Can I wrap a method indirectly like this?

The C++ class:
class Foo { void some_method(int arg) { do_something; } };
And a C wrapper:
void some_method(SV* self, int arg) { // can I store the pointer as IV? SV* inner = SvRV(self); Foo* obj = (Foo*) SvIV(inner); obj->some_method(arg); }
and then simply write XS for that C wrapper?

Replies are listed 'Best First'.
Re: How to use C++ in perl WITH OUT INLINE
by biohisham (Priest) on Jun 25, 2011 at 04:55 UTC
    Take a look at perlxstut and perlxs.

    Basically, the h2xs utility allows you to create a .xs file - that can connect your Perl code with C functions because it holds the routines required - so using it in conjunction with the XSUBPP program gets you to transit from .xs to C code in Perl ...


    David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...
Re: How to use C++ in perl WITH OUT INLINE
by Anonymous Monk on Jun 25, 2011 at 06:27 UTC
    I guess someone will tell me Inline::CPP, but for some reason I'm not going to use it.

    Go ahead and use it, so you can see the XS it generates, because that is all Inline does, it saves you from writing some basic XS.

    Oh look, InlineX::CPP2XS - Convert from Inline C++ code to XS.

    See ExtEmbPerlSrc/chap6/6.8.1/Coordinate.xs from Manning: Extending and Embedding Perl

Re: How to use C++ in perl WITH OUT INLINE
by zentara (Archbishop) on Jun 25, 2011 at 14:18 UTC
      Another recommendation for SWIG. I chose to use SWIG since it seemed much easier than learning the guts of XS.

      In addition to the paper linked by zentara, which is a bit old, you'll also want to consult the SWIG and Perl5 chapter in the manual from the documentation on the SWIG website.

Re: How to use C++ in perl WITH OUT INLINE
by thirdm (Sexton) on Jun 25, 2011 at 11:42 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://911352]
Approved by biohisham
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found