attach#
Prepare a C function once and install it as a named Perl sub.
Synopsis#
package My::Zlib;
my $z = Peta::FFI::dlopen("libz.so.1");
Peta::FFI::attach($z, "zlibVersion", "()p"); # My::Zlib::zlibVersion
Peta::FFI::attach($z, "crc32", "(Lpu32)L", as => "crc");
print zlibVersion(), "\n";
Arguments#
As function, plus as => $sub_name: the Perl name to install, qualified with the calling package unless it contains ::. Without it the C function’s own name is used.
What you get back#
A reference to the installed sub. Redefining the sub (another attach of the same name) releases the function it replaced.