Module: FFI::DataConverter

Included in:
AutoPointer, Enum, StrPtrConverter, StructByReference
Defined in:
lib/ffi/data_converter.rb

Overview

This module is used to extend somes classes and give then a common API.

Most of methods defined here must be overridden.

Instance Method Summary collapse

Instance Method Details

#from_native(value, ctx) ⇒ Object

Convert from a native type.



63
64
65
# File 'lib/ffi/data_converter.rb', line 63

def from_native(value, ctx)
  value
end

#native_type(type) ⇒ Type #native_typeObject

Get native type.

Overloads:

  • #native_type(type) ⇒ Type

    Get native type from type.

    Parameters:

    • type (String, Symbol, Type)

    Returns:

    • (Type)
  • #native_typeObject

    Raises:

    • (NotImplementedError)

      This method must be overridden.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ffi/data_converter.rb', line 45

def native_type(type = nil)
  if type
    @native_type = FFI.find_type(type)
  else
    native_type = @native_type
    unless native_type
      raise NotImplementedError, 'native_type method not overridden and no native_type set'
    end
    native_type
  end
end

#to_native(value, ctx) ⇒ Object

Convert to a native type.



58
59
60
# File 'lib/ffi/data_converter.rb', line 58

def to_native(value, ctx)
  value
end