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, #instantiate_class

Methods included from GirFFI::BuilderHelper

#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_ffi_typesObject



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

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

#callback_symObject



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

def callback_sym
  @classname.to_sym
end

#klassObject



24
25
26
# File 'lib/gir_ffi/builders/callback_builder.rb', line 24

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

#mapping_method_definitionObject



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

def mapping_method_definition
  MappingMethodBuilder.for_callback(info).method_definition
end

#return_ffi_typeObject



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

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

#setup_callbackObject



18
19
20
21
22
# File 'lib/gir_ffi/builders/callback_builder.rb', line 18

def setup_callback
  optionally_define_constant klass, :Callback do
    lib.callback callback_sym, argument_ffi_types, return_ffi_type
  end
end

#setup_classObject



12
13
14
15
16
# File 'lib/gir_ffi/builders/callback_builder.rb', line 12

def setup_class
  setup_callback
  setup_constants
  klass.class_eval mapping_method_definition
end