Don't ask to ask, just ask | |
PerlMonks |
Re: platform agnostic foreign function interface, necessary?, missing?by Joost (Canon) |
on Feb 19, 2009 at 13:32 UTC ( [id://745040]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|