FFI::C::Struct(3pm)

FFI::C::Struct3pm

Structured data instance for ffi

Usage

 use FFI::C::StructDef;
 
 my $def = FFI::C::StructDef->new(
   name  => 'color_t',
   class => 'Color',
   members => [
     red   => 'uint8',
     green => 'uint8',
     blue  => 'uint8',
   ],
 );
 
 my $red = $def->create({ red => 255 });    # creates a FFI::C::Stuct
 
 printf "[%02x %02x %02x]\n", $red->red, $red->green, $red->blue;  # [ff 00 00]
 
 # that red is too bright!
 $red->red(200);
 
 printf "[%02x %02x %02x]\n", $red->red, $red->green, $red->blue;  # [c8 00 00]
 
 
 my $green = Color->new({ green => 255 });  # creates a FFI::C::Stuct
 
 printf "[%02x %02x %02x]\n", $green->red, $green->green, $green->blue;  # [00 ff 00]

Version

version 0.15

Overview

This class represents an instance of a C "struct". This class can be created using "new" on the generated class, if that was specified for the FFI::C::StructDef, or by using the "create" method on FFI::C::StructDef.

For each member defined in the FFI::C::StructDef there is an accessor for the FFI::C::Struct instance.

Constructor

new

 FFI::C::StructDef->new( class => 'User::Struct::Class', ... );
 my $instance = User::Struct::Class->new;

Creates a new instance of the "struct".

Releases

Unchanged in 2 releases since Debian 12 (Bookworm).

  1. 12–13

Author

Graham Ollis <[email protected]>

From libffi-c-perl 0.15-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.