Class: GirFFI::Builders::VFuncBuilder

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

Overview

Implements the creation of a class representing the implementation of a vfunc. This class will be able to turn a proc into an FFI::Function that can serve as such an implementation in C. The class will be namespaced inside class defining the vfunc.

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



50
51
52
53
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 50

def argument_ffi_types
  @argument_ffi_types ||= info.argument_ffi_types.
    unshift(receiver_type_info.to_callback_ffi_type)
end

#container_classObject



42
43
44
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 42

def container_class
  @container_class ||= Builder.build_class(container_info)
end

#container_infoObject



46
47
48
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 46

def container_info
  @container_info ||= info.container
end

#klassObject



20
21
22
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 20

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

#mapping_method_definitionObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 24

def mapping_method_definition
  arg_infos = info.args
  arg_infos << ErrorArgumentInfo.new if info.throws?

  receiver_info = ReceiverArgumentInfo.new receiver_type_info
  return_value_info = ReturnValueInfo.new(info.return_type,
                                          info.caller_owns,
                                          info.skip_return?)

  MappingMethodBuilder.for_vfunc(receiver_info,
                                 arg_infos,
                                 return_value_info).method_definition
end

#receiver_type_infoObject



38
39
40
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 38

def receiver_type_info
  ReceiverTypeInfo.new(container_info)
end

#return_ffi_typeObject



55
56
57
# File 'lib/gir_ffi/builders/vfunc_builder.rb', line 55

def return_ffi_type
  @return_ffi_type ||= info.return_ffi_type
end

#setup_classObject



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

def setup_class
  setup_constants
  klass.class_eval mapping_method_definition
end