Sha256: 54c515cd2d5a3066040b4fa447ebfa0c1dfeb33fdfa894c257f59dc7c557cd94

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'gir_ffi/builders/base_type_builder'
require 'gir_ffi/builders/mapping_method_builder'
require 'gir_ffi/callback_base'

module GirFFI
  module Builders
    # 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.
    class CallbackBuilder < BaseTypeBuilder
      def instantiate_class
        setup_class unless already_set_up
      end

      def setup_class
        setup_callback
        setup_constants
        klass.class_eval mapping_method_definition
      end

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

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

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

      def callback_sym
        @classname.to_sym
      end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gir_ffi-0.7.4 lib/gir_ffi/builders/callback_builder.rb
gir_ffi-0.7.3 lib/gir_ffi/builders/callback_builder.rb