Class: FFI::Struct

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-compiler/fake_ffi/ffi.rb

Constant Summary collapse

TypeMap =
{}

Class Method Summary collapse

Class Method Details

.by_refObject



166
167
168
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 166

def self.by_ref
  StructByReference.new(self)
end

.by_valueObject



162
163
164
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 162

def self.by_value
  StructByValue.new(self)
end

.find_type(type) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 151

def self.find_type(type)
  t = TypeMap[type]
  return t unless t.nil?

  if type.is_a?(Class) && type < Struct
    return TypeMap[type] = StructByValue.new(type)
  end

  TypeMap[type] = FFI.find_type(type)
end

.layout(*args) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/ffi-compiler/fake_ffi/ffi.rb', line 140

def self.layout(*args)
  fields = []
  i = 0
  while i < args.length
    fields << { name: args[i], type: find_type(args[i+1]) }
    i += 2
  end
  FFI.exporter.struct(self.to_s, fields)
end