NAME¶
NativeCall - Perl 5 interface to foreign functions in Perl code without XS
SYNOPSIS¶
use parent qw(NativeCall);
use feature 'say';
sub cdio_eject_media_drive :Args(string) :Native(cdio) {}
sub cdio_close_tray :Args(string, int) :Native(cdio) {}
say "Gimme a CD!";
cdio_eject_media_drive undef;
sleep 1;
say "Ha! Too slow!";
cdio_close_tray undef, 0;
sub fmax :Args(double, double) :Native :Returns(double) {}
say "fmax(2.0, 3.0) = " . fmax(2.0, 3.0);
# avoid Perl built in also called "abs"
sub myabs :Args(int) :Native :Returns(int) :Symbol(abs) {}
say "abs(-3) = " . abs(-3);
DESCRIPTION¶
Mimics the "NativeCall" module and interface
from Perl 6. Uses FFI::Platypus, by the mighty Graham Ollis, for the actual
hard work. Uses inheritance and attributes.
See examples/troll.pl for the example given above in
SYNOPSIS.
ATTRIBUTES¶
- Native
- If an argument is given, try to load from that library. If none given, use
what is already loaded.
- Args
- A comma-separated list of FFI::Platypus::Types. All types are supported,
including closures.
- Returns
- A single FFI::Platypus::Type.
- Symbol
- The native symbol name, if different from the Perl sub name.