NativeCall(3pm) | User Contributed Perl Documentation | NativeCall(3pm) |
NativeCall - Perl 5 interface to foreign functions in Perl code without XS
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);
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.
This module is entirely inspired by the article about Perl 6 NativeCall at <http://blogs.perl.org/users/zoffix_znet/2016/05/perl-6-nativecall-look-ma-im-a-c-programmer-1.html>. All credit for clear explanation to Zoffix. All brickbats to me.
2022-06-16 | perl v5.34.0 |