FFI-Platypus

 view release on metacpan or  search on metacpan

lib/FFI/Platypus.pm  view on Meta::CPAN


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

Prepares a code reference so that it can be used as a FFI closure (a
Perl subroutine that can be called from C code).  For details on
closures, see L<FFI::Platypus::Type#Closures> and L<FFI::Platypus::Closure>.

=head2 cast

 my $converted_value = $ffi->cast($original_type, $converted_type, $original_value);

The C<cast> function converts an existing I<$original_value> of type
I<$original_type> into one of type I<$converted_type>.  Not all types
are supported, so care must be taken.  For example, to get the address
of a string, you can do this:

 my $address = $ffi->cast('string' => 'opaque', $string_value);

Something that won't work is trying to cast an array to anything:

 my $address = $ffi->cast('int[10]' => 'opaque', \@list);  # WRONG

=head2 attach_cast

 $ffi->attach_cast("cast_name", $original_type, $converted_type);
 $ffi->attach_cast("cast_name", $original_type, $converted_type, \&wrapper);
 my $converted_value = cast_name($original_value);

This function attaches a cast as a permanent xsub.  This will make it
faster and may be useful if you are calling a particular cast a lot.

[version 1.26]

A wrapper may be added as the last argument to C<attach_cast> and works
just like the wrapper for C<attach> and C<function> methods.

=head2 sizeof

 my $size = $ffi->sizeof($type);
 my $size = FFI::Platypus->sizeof($type);

Returns the total size of the given type in bytes.  For example to get
the size of an integer:

 my $intsize = $ffi->sizeof('int');   # usually 4
 my $longsize = $ffi->sizeof('long'); # usually 4 or 8 depending on platform

You can also get the size of arrays

 my $intarraysize = $ffi->sizeof('int[64]');  # usually 4*64
 my $intarraysize = $ffi->sizeof('long[64]'); # usually 4*64 or 8*64
                                              # depending on platform

Keep in mind that "pointer" types will always be the pointer / word size
for the platform that you are using.  This includes strings, opaque and
pointers to other types.

This function is not very fast, so you might want to save this value as
a constant, particularly if you need the size in a loop with many
iterations.

=head2 alignof

[version 0.21]

 my $align = $ffi->alignof($type);

Returns the alignment of the given type in bytes.

=head2 kindof

[version 1.24]

 my $kind = $ffi->kindof($type);

Returns the kind of a type.  This is a string with a value of one of

=over 4

=item C<void>

=item C<scalar>

=item C<string>

=item C<closure>

=item C<record>

=item C<record-value>

=item C<pointer>

=item C<array>

=item C<object>

=back

=head2 countof

[version 1.24]

 my $count = $ffi->countof($type);

For array types returns the number of elements in the array (returns 0 for variable length array).
For the C<void> type returns 0.  Returns 1 for all other types.

=head2 def

[version 1.24]

 $ffi->def($package, $type, $value);
 my $value = $ff->def($package, $type);

This method allows you to store data for types.  If the C<$package> is not provided, then the
caller's package will be used.  C<$type> must be a legal Platypus type for the L<FFI::Platypus>
instance.

=head2 unitof



( run in 1.844 second using v1.01-cache-2.11-cpan-b16cb0d3907 )