Class: FFI::StructByReference
- Inherits:
-
Object
- Object
- FFI::StructByReference
- Includes:
- DataConverter
- Defined in:
- lib/ffi/struct_by_reference.rb
Overview
This class includes the DataConverter module.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#struct_class ⇒ Object
readonly
Returns the value of attribute struct_class.
Instance Method Summary collapse
-
#from_native(value, ctx) ⇒ Struct
Create a struct from content of memory
value
. -
#initialize(struct_class) ⇒ StructByReference
constructor
A new instance of StructByReference.
-
#native_type ⇒ Object
Always get Type::POINTER.
-
#to_native(value, ctx) ⇒ AbstractMemory
Pointer on
value
.
Constructor Details
#initialize(struct_class) ⇒ StructByReference
Returns a new instance of StructByReference.
39 40 41 42 43 44 |
# File 'lib/ffi/struct_by_reference.rb', line 39 def initialize(struct_class) unless Class === struct_class and struct_class < FFI::Struct raise TypeError, 'wrong type (expected subclass of FFI::Struct)' end @struct_class = struct_class end |
Instance Attribute Details
#struct_class ⇒ Object (readonly)
Returns the value of attribute struct_class.
36 37 38 |
# File 'lib/ffi/struct_by_reference.rb', line 36 def struct_class @struct_class end |
Instance Method Details
#from_native(value, ctx) ⇒ Struct
Create a struct from content of memory value
.
68 69 70 |
# File 'lib/ffi/struct_by_reference.rb', line 68 def from_native(value, ctx) @struct_class.new(value) end |
#native_type ⇒ Object
Always get Type::POINTER.
47 48 49 |
# File 'lib/ffi/struct_by_reference.rb', line 47 def native_type FFI::Type::POINTER end |
#to_native(value, ctx) ⇒ AbstractMemory
Returns Pointer on value
.
54 55 56 57 58 59 60 61 62 |
# File 'lib/ffi/struct_by_reference.rb', line 54 def to_native(value, ctx) return Pointer::NULL if value.nil? unless @struct_class === value raise TypeError, "wrong argument type #{value.class} (expected #{@struct_class})" end value.pointer end |