Module: FFI::StructWrapper

Extended by:
Accessors::ClassMethods, ClassMethods
Includes:
Accessors
Included in:
Libfuse::FuseBuf, Libfuse::FuseFileInfo, Stat
Defined in:
lib/ffi/struct_wrapper.rb

Overview

Helper to wrap structs with ugly names and attribute clashes with FFI::Struct (eg size)

Examples:

class MyStruct
  include FFI::StructWrapper
  native_struct(MyNativeStruct)

  #!@attribute [rw] field
  ffi_attr_accessor :field
end

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

by_ref, by_value

Methods included from Accessors::ClassMethods

attr_accessor, attr_reader, attr_writer, ffi_attr_accessor, ffi_attr_reader, ffi_attr_reader_method, ffi_attr_readers, ffi_attr_writer, ffi_attr_writer_method, ffi_attr_writers, ffi_bitflag_accessor, ffi_bitflag_reader, ffi_bitflag_writer, ffi_public_attr_readers, ffi_public_attr_writers

Methods included from Accessors

#ffi_attr_fill, #ffi_attr_reader_member, #ffi_attr_writer_member, #fill, #inspect, #to_h

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Pass unimplemented methods on to #native underlying struct



114
115
116
# File 'lib/ffi/struct_wrapper.rb', line 114

def method_missing(method, *args)
  @native.send(method, *args)
end

Instance Attribute Details

#nativeFFI::Struct (readonly)

Returns the underlying native struct.

Returns:

  • (FFI::Struct)

    the underlying native struct



94
95
96
# File 'lib/ffi/struct_wrapper.rb', line 94

def native
  @native
end

Instance Method Details

#[](member_or_attr) ⇒ Object

Get attribute



102
103
104
105
# File 'lib/ffi/struct_wrapper.rb', line 102

def [](member_or_attr)
  _attr, member = ffi_attr_reader_member(member_or_attr, member_or_attr)
  @native[member]
end

#[]=(member_or_attr, val) ⇒ Object

Set attribute



108
109
110
111
# File 'lib/ffi/struct_wrapper.rb', line 108

def []=(member_or_attr, val)
  _attr, member = ffi_attr_writer_member(member_or_attr, member_or_attr)
  @native[member] = val
end