- BUGS AND LIMITATIONS
- LICENCE AND COPYRIGHT
- DISCLAIMER OF WARRANTY
FFI::Me - Turn foreign functions into perl functions or methods without writing XS.
This document describes FFI::Me version 0.01
use FFI::Me; ffi puts => ( rv => ffi::int, arg => [ffi::str], ); puts("Say what!");
Uses in an OO package with a method name that differs from the symbol in the library:
ffi cosine => ( lib => 'libm.so' rv => ffi::double, arg => [ffi::double], sym => 'cos', method => 1, );
Then later when we have an object:
Note: To make your code more portable you could do something like:
lib => $^O eq 'darwin' ? 'libm.dylib' : 'libm.so',
or use something like FFI::CheckLib.
libffi (low-level FFI via FFI::Raw in this case) is a really neat way to get access to foreign functions from inside perl.
This module encapsulates the common task of creating the interface via the low-level FFI and then making a higher-level function or method to wrap it.
The simple syntax is the sugary style prefered by most MOPish code.
Syntax: ffi NAME => (OPTIONS);
Creates a function or method called "NAME" from a foreign function desribed via NAME and OPTIONS.
See "SYNOPSIS" for examples.
The options are as follows:
The library that contains the symbol we are interested in.
Default: undef (i.e. search in the main program for the foreign function)
The type for the return value of the symbol we are interested in.
An array ref of types of the arguments taken by the symbol we are interested in.
Default: empty list
The name of the foreign function symbol in our lib. Useful when you want your perl function or method to be a different name than the foreign function symbol you are interfacing with.
Default: The NAME passed to ffi().
Boolean. If true, it will create the symbol as a method instead of a function.
Each type has a function that will return the type suitable for “rv” and “arg”.
We use the ffi:: name space for these functions to avoid importing them while still keeping them short.
Throws no warnings or errors of its own.
The underlying low-level library throws an exception when it can’t do what we’re asking it to.
No bugs have been reported.
Please report any bugs or feature requests to
firstname.lastname@example.org, or through the web interface at http://rt.cpan.org.
Possibly some library lookup ability to allow for things like
lib = 'libm'> witout needing to
$^O eq 'darwin' ? 'libm.dylib' : 'libm.so'.
Copyright (c) 2015, Daniel Muey
<http://drmuey.com/cpan_contact.pl>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.