Class: C2FFI4RB::BindGen

Inherits:
Object
  • Object
show all
Defined in:
lib/c2ffi4rb/bind_gen.rb

Constant Summary collapse

DEFAULT_TYPE_TABLE =
{
  ':signed-int' => ':int',
  ':unsigned-int' => ':uint',
  ':signed-char' => ':char',
  ':unsigned-char' => ':uchar',
  ':signed-short' => ':short',
  ':unsigned-short' => ':ushort',
  ':long-long' => ':long_long',
  ':ulong-long' => ':ulong_long',
  ':long-double' => ':long_double',
  ':signed-long' => ':long',
  ':unsigned-long' => ':ulong',
  ':unsigned-long-long' => ':ulong_long',
  ':function-pointer' => ':pointer'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_table = {}) ⇒ BindGen

Initialize with optional type conversion table



29
30
31
32
33
34
35
36
# File 'lib/c2ffi4rb/bind_gen.rb', line 29

def initialize(type_table = {})
  @type_table = DEFAULT_TYPE_TABLE.merge(type_table)
  @struct_type = []
  @toplevels = []
  @anon_counter = 0
  @anon_enum_ids = []
  @typedefs = {}
end

Class Method Details

.generate_bindings(arr) ⇒ Object

Class method to create instance and generate bindings



24
25
26
# File 'lib/c2ffi4rb/bind_gen.rb', line 24

def self.generate_bindings(arr)
  new.generate_bindings(arr)
end

Instance Method Details

#generate_bindings(arr) ⇒ Object

Main entry point: process all forms and output Ruby FFI code



39
40
41
42
# File 'lib/c2ffi4rb/bind_gen.rb', line 39

def generate_bindings(arr)
  arr.each { |form| process_toplevel(form) }
  puts @toplevels.join("\n\n")
end