FFI-Platypus
view release on metacpan or search on metacpan
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 FFI::Platypus::Type#Closures and FFI::Platypus::Closure.
cast
my $converted_value = $ffi->cast($original_type, $converted_type, $original_value);
The cast function converts an existing $original_value of type
$original_type into one of type $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
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 attach_cast and works
just like the wrapper for attach and function methods.
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.
alignof
[version 0.21]
my $align = $ffi->alignof($type);
Returns the alignment of the given type in bytes.
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
void
scalar
string
closure
record
record-value
pointer
array
object
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 void type returns 0. Returns 1 for
all other types.
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 $package is not
provided, then the caller's package will be used. $type must be a legal
Platypus type for the FFI::Platypus instance.
unitof
[version 1.24]
( run in 0.683 second using v1.01-cache-2.11-cpan-71847e10f99 )