Module: FFI

Defined in:
lib/ffi-compiler/task.rb,
lib/ffi-compiler/loader.rb,
lib/ffi-compiler/export_task.rb,
lib/ffi-compiler/compile_task.rb,
lib/ffi-compiler/fake_ffi/ffi.rb,
lib/ffi-compiler/fake_ffi/ffi-compiler/loader.rb

Defined Under Namespace

Modules: Compiler, Library Classes: CallbackInfo, Exporter, Function, Struct, StructByReference, StructByValue, Type

Constant Summary collapse

PrimitiveTypes =
{
    :void => 'void',
    :bool => 'bool',
    :string => 'const char *',
    :char => 'char',
    :uchar => 'unsigned char',
    :short => 'short',
    :ushort => 'unsigned short',
    :int => 'int',
    :uint => 'unsigned int',
    :long => 'long',
    :ulong => 'unsigned long',
    :long_long => 'long long',
    :ulong_long => 'unsigned long long',
    :float => 'float',
    :double => 'double',
    :long_double => 'long double',
    :pointer => 'void *',
    :int8 => 'int8_t',
    :uint8 => 'uint8_t',
    :int16 => 'int16_t',
    :uint16 => 'uint16_t',
    :int32 => 'int32_t',
    :uint32 => 'uint32_t',
    :int64 => 'int64_t',
    :uint64 => 'uint64_t',
    :buffer_in => 'const in void *',
    :buffer_out => 'out void *',
    :buffer_inout => 'inout void *',
    :varargs => '...'
}
TypeMap =
{}

Class Method Summary collapse

Class Method Details

.exporterObject



7
8
9
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 7

def self.exporter
  @@exporter ||= Exporter.new(nil)
end

.exporter=(exporter) ⇒ Object



3
4
5
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 3

def self.exporter=(exporter)
  @@exporter = exporter
end

.find_type(type) ⇒ Object

Raises:

  • (TypeError)


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 80

def self.find_type(type)
  return type if type.is_a?(Type) or type.is_a?(CallbackInfo)

  t = TypeMap[type]
  return t unless t.nil?

  if PrimitiveTypes.has_key?(type)
    return TypeMap[type] = Type.new(PrimitiveTypes[type])
  end
  raise TypeError.new("cannot resolve type #{type}")
end