Sha256: 07ac616a4fd184234ae5b0dd6485a4bbfd64a5118d905e07cbf24c025e08c005

Contents?: true

Size: 1.87 KB

Versions: 10

Compression:

Stored size: 1.87 KB

Contents

require 'gir_ffi/return_value_info'
require 'gir_ffi/builders/base_type_builder'
require 'gir_ffi/builders/mapping_method_builder'
require 'gir_ffi/receiver_type_info'
require 'gir_ffi/receiver_argument_info'
require 'gir_ffi/callback_base'

module GirFFI
  module Builders
    # 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.
    class VFuncBuilder < BaseTypeBuilder
      def setup_class
        setup_constants
        klass.class_eval mapping_method_definition
      end

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

      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

      def receiver_type_info
        ReceiverTypeInfo.new(container_info)
      end

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

      def container_info
        @container_info ||= info.container
      end

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gir_ffi-0.9.2 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.9.1 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.9.0 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.6 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.5 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.4 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.3 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.2 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.1 lib/gir_ffi/builders/vfunc_builder.rb
gir_ffi-0.8.0 lib/gir_ffi/builders/vfunc_builder.rb