Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Calling C++ functions from Perl without using xsubpp

by andal (Hermit)
on Sep 19, 2012 at 08:36 UTC ( [id://994430]=note: print w/replies, xml ) Need Help??


in reply to Calling C++ functions from Perl without using xsubpp

Actually, xsubpp produces set of code that does conversion from structures specific to perl to those understandable for your code. In fact, you can write C code that works with perl structures directly, in which case no conversion has to be done. Just make your function work with AV* or for example SV*.

Inline::C and Co. provide automatic conversion to some set of common types, just like XS does. If using these types is enough, then you don't need anything else but those modules. If you have to work with more complex data structures, then you have to understand perl's guts. Read perldoc perlguts. Then read perldoc perlxs to learn how to work with XS. Then read perldoc perlapi to see which functions are available to you for working with perl's structures. XS shall only simplify certain things for you.

After all, you can think of Perl as of C library providing certain API.

  • Comment on Re: Calling C++ functions from Perl without using xsubpp

Replies are listed 'Best First'.
Re^2: Calling C++ functions from Perl without using xsubpp
by syphilis (Archbishop) on Sep 19, 2012 at 09:24 UTC
    Inline::C and Co. provide automatic conversion to some set of common types, just like XS does. If using these types is enough, then you don't need anything else but those modules. If you have to work with more complex data structures, then you have to .... learn how to work with XS.

    Perhaps I've misread (and inappropriately edited) that excerpt from your post, but it seems to me that you're saying that Inline::C is good only for some limited set of C types.
    That's not the case - if it can be done using XS then it can be done using Inline::C. After all, Inline::C is little more than a utility that generates an XS file, which it then compiles.
    (I keep thinking there must be *some* feature of XS that Inline::C can't reproduce ... and I'd love to see some examples that validate such thinking.)

    Cheers,
    Rob

      Well, I guess I have expressed myself imprecise. My point was not so much about abilities of Inline::C. My point was about need to learn perl guts if one needs to work with more complex input/output parameters. In this case learning XS comes in mostly for understanding what is happening. Though, probably some people can write code without knowing how their code turns into program :)

        My point was about need to learn perl guts if one needs to work with more complex input/output parameters

        Yes, that is so ... and I probably should have realised that was what you were saying.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://994430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found