P5NCI seems to be pretty much equivalent to ruby's FFI, though I haven't used either.

There are some issues with this kind of approach though, especially in a multi-platform environment. Mainly, it doesn't rely on a C compiler or any of the header files which is great if need to install it on a system for which you don't have a C compiler or header files but it also means you'll end up replicating the header files in the FFI code. And structures and function arguments tend to differ over different operating systems.

A simple example of this problem that I've ran into when using the CFFI system: the values of the RTLD_* constants (used as the MODE argument to dlopen) are different for at least Linux & BSD, but if you don't know that, the code will probably run but not do what you want on one of the systems. The suggested way to work around that is to parse the header files yourself - that is obviously not a very good way to go about things.

On the other hand, XS is really pretty good, as portable as C is (which is exactly the right amount of portable) and the only requirement is that you've got a decent C compiler + header files available. With strawberry perl, that should mean it's free for every major OS that perl runs on. Yes it's a bit more complicated, but not really that much. Get the book if you want to good introduction.


In reply to Re: platform agnostic foreign function interface, necessary?, missing? by Joost
in thread platform agnostic foreign function interface, necessary?, missing? by jettero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.