FFI::Raw - Raw FFI library for Perl
version 0.07
use FFI::Raw; my $cos = FFI::Raw -> new( 'libm.so', 'cos', FFI::Raw::double, # return value FFI::Raw::double # arg #1 ); say $cos -> call(2.0);
FFI::Raw provides a raw foreign function interface for Perl based on libffi. It can access and call functions exported by shared libraries without the need to write C/XS code.
Dynamic symbols can be automatically resolved at runtime so that the only information needed to use FFI::Raw is the name (or path) of the target library, the name of the function to call and its signature (though it is also possible to pass a function pointer).
Note that this module has nothing to do with FFI.
Attention: this is experimental code, use at your own risk
Create a new FFI::Raw object. It loads $library, finds the function $function with return type $return_type and creates a calling interface.
FFI::Raw
$library
$function
$return_type
This function takes also a variable number of types, representing the argument of the wanted function.
Create a new FFI::Raw object from the $function_ptr function pointer.
$function_ptr
Execute the FFI::Raw function $self. This function takes also a variable number of arguments, which are passed to the called function. The argument types must match the types passed to new.
$self
new
Allocate $number bytes and return a FFI::Raw::MemPtr pointing to the allocated memory. This can be passed to functions which take a FFI::Raw::ptr argument. A FFI::Raw::MemPtr can be converted to a Perl string using the tostr() method.
$number
FFI::Raw::MemPtr
tostr()
Create a callback, given a code reference $coderef, its return type $ret_type and the argument types it takes.
$coderef
$ret_type
Return a FFI::Raw void type.
Return a FFI::Raw integer type.
Return a FFI::Raw unsigned integer type.
Return a FFI::Raw short integer type.
Return a FFI::Raw unsigned short integer type.
Return a FFI::Raw char type.
Return a FFI::Raw unsigned char type.
Return a FFI::Raw float type.
Return a FFI::Raw double type.
Return a FFI::Raw string type.
Return a FFI::Raw pointer type.
Alessandro Ghedini <alexbio@cpan.org>
FFI, Ctypes
Copyright 2012 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install FFI::Raw, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FFI::Raw
CPAN shell
perl -MCPAN -e shell install FFI::Raw
For more information on module installation, please visit the detailed CPAN module installation guide.