NAME

FFI::Raw - Perl bindings to the portable FFI library (libffi)

VERSION

version 0.32

SYNOPSIS

    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);

DESCRIPTION

FFI::Raw provides a low-level foreign function interface (FFI) for Perl based on libffi. In essence, 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 obtained, for example, using DynaLoader).

Note that this module has nothing to do with FFI.

METHODS

new( $library, $function, $return_type [, $arg_type ...] )

Create a new FFI::Raw object. It loads $library, finds the function $function with return type $return_type and creates a calling interface.

If $library is undef then the function is searched in the main program.

This method also takes a variable number of types, representing the arguments of the wanted function.

new_from_ptr( $function_ptr, $return_type [, $arg_type ...] )

Create a new FFI::Raw object from the $function_ptr function pointer.

This method also takes a variable number of types, representing the arguments of the wanted function.

call( [$arg ...] )

Execute the FFI::Raw function. This methoed also takes a variable number of arguments, which are passed to the called function. The argument types must match the types passed to new (or new_from_ptr).

The FFI::Raw object can be used as a CODE reference as well. Dereferencing the object will work just like call():

    $cos -> call(2.0); # normal call() call
    $cos -> (2.0);     # dereference as CODE ref

This works because FFI::Raw overloads the &{} operator.

coderef( )

Return a code reference of a given FFI::Raw.

SUBROUTINES

memptr( $length )

Create a FFI::Raw::MemPtr. This is a shortcut for FFI::Raw::MemPtr->new(...).

callback( $coderef, $ret_type [, $arg_type ...] )

Create a FFI::Raw::Callback. This is a shortcut for FFI::Raw::Callback->new(...).

TYPES

FFI::Raw::void

Return a FFI::Raw void type.

FFI::Raw::int

Return a FFI::Raw integer type.

FFI::Raw::uint

Return a FFI::Raw unsigned integer type.

FFI::Raw::short

Return a FFI::Raw short integer type.

FFI::Raw::ushort

Return a FFI::Raw unsigned short integer type.

FFI::Raw::long

Return a FFI::Raw long integer type.

FFI::Raw::ulong

Return a FFI::Raw unsigned long integer type.

FFI::Raw::int64

Return a FFI::Raw 64 bit integer type. This requires Math::Int64 to work.

FFI::Raw::uint64

Return a FFI::Raw unsigned 64 bit integer type. This requires Math::Int64 to work.

FFI::Raw::char

Return a FFI::Raw char type.

FFI::Raw::uchar

Return a FFI::Raw unsigned char type.

FFI::Raw::float

Return a FFI::Raw float type.

FFI::Raw::double

Return a FFI::Raw double type.

FFI::Raw::str

Return a FFI::Raw string type.

FFI::Raw::ptr

Return a FFI::Raw pointer type.

AUTHOR

Alessandro Ghedini <alexbio@cpan.org>

SEE ALSO

FFI, Ctypes

LICENSE AND COPYRIGHT

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.