1FFI::Platypus::Closure(U3s)er Contributed Perl DocumentatFiFoIn::Platypus::Closure(3)
2
3
4
6 FFI::Platypus::Closure - Platypus closure object
7
9 version 0.94
10
12 create closure with OO interface
13
14 use FFI::Platypus::Closure;
15 my $closure = FFI::Platypus::Closure->new(sub { print "hello world\n" });
16
17 create closure from Platypus object
18
19 use FFI::Platypus;
20 my $ffi = FFI::Platypus->new;
21 my $closure = $ffi->closure(sub { print "hello world\n" });
22
23 use closure
24
25 $ffi->function(foo => ['()->void'] => 'void')->call($closure);
26
28 This class represents a Perl code reference that can be called from
29 compiled code. When you create a closure object, you can pass it into
30 any function that expects a function pointer. Care needs to be taken
31 with closures because compiled languages typically have a different way
32 of handling lifetimes of objects. You have to make sure that if the
33 compiled code is going to call a closure that the closure object is
34 still in scope somewhere, or has been made sticky, otherwise you may
35 get a segment violation or other mysterious crash.
36
38 new
39 my $closure = FFI::Platypus::Closure->new($coderef);
40
41 Create a new closure object; $coderef must be a subroutine code
42 reference.
43
45 call
46 $closure->call(@arguments);
47 $closure->(@arguments);
48
49 Call the closure from Perl space. May also be invoked by treating the
50 closure object as a code reference.
51
52 sticky
53 $closure->sticky;
54
55 Mark the closure sticky, meaning that it won't be free'd even if all
56 the reference of the object fall out of scope.
57
58 unstick
59 $closure->unstick;
60
61 Unmark the closure as sticky.
62
64 Author: Graham Ollis <plicease@cpan.org>
65
66 Contributors:
67
68 Bakkiaraj Murugesan (bakkiaraj)
69
70 Dylan Cali (calid)
71
72 pipcet
73
74 Zaki Mughal (zmughal)
75
76 Fitz Elliott (felliott)
77
78 Vickenty Fesunov (vyf)
79
80 Gregor Herrmann (gregoa)
81
82 Shlomi Fish (shlomif)
83
84 Damyan Ivanov
85
86 Ilya Pavlov (Ilya33)
87
88 Petr Pisar (ppisar)
89
90 Mohammad S Anwar (MANWAR)
91
93 This software is copyright (c) 2015,2016,2017,2018,2019 by Graham
94 Ollis.
95
96 This is free software; you can redistribute it and/or modify it under
97 the same terms as the Perl 5 programming language system itself.
98
99
100
101perl v5.30.0 2019-07-26 FFI::Platypus::Closure(3)