Class: GirFFI::Builders::CallbackBuilder

Inherits:
GirFFI::BaseTypeBuilder show all
Defined in:
lib/gir_ffi/builders/callback_builder.rb

Overview

Implements the creation of a callback type. The type will be attached to the appropriate namespace module, and will be defined as a callback for FFI.

Instance Attribute Summary

Attributes inherited from GirFFI::BaseTypeBuilder

#info

Instance Method Summary collapse

Methods inherited from GirFFI::BaseTypeBuilder

#build_class, #initialize

Methods included from GirFFI::BuilderHelper

#const_defined_for, #get_or_define_class, #get_or_define_module, #optionally_define_constant

Constructor Details

This class inherits a constructor from GirFFI::BaseTypeBuilder

Instance Method Details

#argument_typesObject



39
40
41
# File 'lib/gir_ffi/builders/callback_builder.rb', line 39

def argument_types
  @argument_types ||= @info.argument_ffi_types
end

#callback_symObject



35
36
37
# File 'lib/gir_ffi/builders/callback_builder.rb', line 35

def callback_sym
  @classname.to_sym
end

#instantiate_classObject



11
12
13
# File 'lib/gir_ffi/builders/callback_builder.rb', line 11

def instantiate_class
  setup_class unless already_set_up
end

#klassObject



27
28
29
# File 'lib/gir_ffi/builders/callback_builder.rb', line 27

def klass
  @klass ||= get_or_define_class namespace_module, @classname, CallbackBase
end

#mapping_method_definitionObject



31
32
33
# File 'lib/gir_ffi/builders/callback_builder.rb', line 31

def mapping_method_definition
  MappingMethodBuilder.for_callback(info.args, info.return_type).method_definition
end

#return_typeObject



43
44
45
# File 'lib/gir_ffi/builders/callback_builder.rb', line 43

def return_type
  @return_type ||= @info.return_ffi_type
end

#setup_callbackObject



21
22
23
24
25
# File 'lib/gir_ffi/builders/callback_builder.rb', line 21

def setup_callback
  optionally_define_constant klass, :Callback do
    lib.callback callback_sym, argument_types, return_type
  end
end

#setup_classObject



15
16
17
18
19
# File 'lib/gir_ffi/builders/callback_builder.rb', line 15

def setup_class
  setup_callback
  setup_constants
  klass.class_eval mapping_method_definition
end