logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FFI::Platypus::Closure - Platypus closure object

Author

       Author: Graham Ollis <plicease@cpan.org>

       Contributors:

       Bakkiaraj Murugesan (bakkiaraj)

       Dylan Cali (calid)

       pipcet

       Zaki Mughal (zmughal)

       Fitz Elliott (felliott)

       Vickenty Fesunov (vyf)

       Gregor Herrmann (gregoa)

       Shlomi Fish (shlomif)

       Damyan Ivanov

       Ilya Pavlov (Ilya33)

       Petr Písař (ppisar)

       Mohammad S Anwar (MANWAR)

       Håkon Hægland (hakonhagland, HAKONH)

       Meredith (merrilymeredith, MHOWARD)

       Diab Jerius (DJERIUS)

       Eric Brine (IKEGAMI)

       szTheory

       José Joaquín Atria (JJATRIA)

       Pete Houston (openstrike, HOUSTON)

       Lukas Mai (MAUKE)

Constructor

new
        my $closure = FFI::Platypus::Closure->new($coderef);

       Create a new closure object; $coderef must be a subroutine code reference.

Description

       This class represents a Perl code reference that can be called from compiled code.  When you create a
       closure object, you can pass it into any function that expects a function pointer.  Care needs to be
       taken with closures because compiled languages typically have a different way of handling lifetimes of
       objects.  You have to make sure that if the compiled code is going to call a closure that the closure
       object is still in scope somewhere, or has been made sticky, otherwise you may get a segment violation or
       other mysterious crash.

Methods

call
        $closure->call(@arguments);
        $closure->(@arguments);

       Call the closure from Perl space.  May also be invoked by treating the closure object as a code
       reference.

   sticky
        $closure->sticky;

       Mark the closure sticky, meaning that it won't be free'd even if all the reference of the object fall out
       of scope.

   unstick
        $closure->unstick;

       Unmark the closure as sticky.

Name

       FFI::Platypus::Closure - Platypus closure object

Synopsis

       create closure with OO interface

        use FFI::Platypus::Closure;
        my $closure = FFI::Platypus::Closure->new(sub { print "hello world\n" });

       create closure from Platypus object

        use FFI::Platypus 2.00;
        my $ffi = FFI::Platypus->new( api => 2 );
        my $closure = $ffi->closure(sub { print "hello world\n" });

       use closure

        $ffi->function(foo => ['()->void'] => 'void')->call($closure);

Version

       version 2.10

See Also