Alt-FFI-libffi
view release on metacpan or search on metacpan
$ffi->function($addr => \@args_types => $ret_type)->call(@_);
}
sub callback
{
my($signature, $sub) = @_;
my $ffi = _ffi($signature);
my($ret_type, @args_types) = map { $typemap{$_} } split //, $signature;
my $type = '(' . join(',', @args_types) . ')->' . $ret_type;
my $closure = $ffi->closure($sub);
bless {
addr => $ffi->cast($type => 'opaque', $closure),
sub => $sub,
closure => $closure,
}, 'FFI::Callback';
}
package FFI::Callback;
sub addr { shift->{addr} }
lib/FFI/Library.pm view on Meta::CPAN
sub new
{
my($class, $libname, $flags) = @_;
Carp::croak('Usage: $lib = FFI::Library->new($filename [, $flags ])')
unless @_ <= 3;
$flags ||= 0;
if(! defined $libname)
{
return bless {
impl => 'null',
}, $class;
}
elsif(ref $libname and int($libname) == int(\$0))
{
return $class->_dl_impl(undef, undef);
}
elsif(_is_win)
{
return $class->_dl_impl($libname, undef);
lib/FFI/Library.pm view on Meta::CPAN
$libname,
$flags == 0x01 ? FFI::Platypus::Lang::DL::RTLD_GLOBAL() : undef,
);
}
else
{
require DynaLoader;
my $so = DynaLoader::dl_findfile($libname) || $libname;
my $handle = DynaLoader::dl_load_file($so, $flags || 0);
return unless $handle;
return bless {
impl => 'dynaloader',
handle => $handle,
}, $class;
}
}
sub _dl_impl
{
my($class, $path, $flags) = @_;
require FFI::Platypus::DL;
$flags = FFI::Platypus::DL::RTLD_PLATYPUS_DEFAULT()
unless defined $flags;
my $handle = FFI::Platypus::DL::dlopen($path, $flags);
return unless defined $handle;
bless { impl => 'dl', handle => $handle }, $class;
}
sub address
{
my($self, $name) = @_;
if($self->{impl} eq 'dl')
{
return FFI::Platypus::DL::dlsym($self->{handle}, $name);
}
( run in 0.345 second using v1.01-cache-2.11-cpan-de7293f3b23 )