Sha256: 1e5351a944a9dbff6a73dd0ad8d6dc966bb84e920bbf185acd2d2467c9144289

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

require 'gir_ffi/builder/type/base'
module GirFFI
  module Builder
    module Type

      # 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 Callback < Base
        def instantiate_class
          @klass = optionally_define_constant namespace_module, @classname do
            lib.callback callback_sym, argument_types, return_type
          end
        end

        def pretty_print
          args = argument_types.map do |arg|
            arg.is_a?(FFI::Enum) ? arg.tag : arg.inspect
          end
          return "#{@classname} = Lib.callback #{callback_sym.inspect}, " +
            "[#{args.join(', ')}], #{return_type.inspect}"
        end

        def callback_sym
          @classname.to_sym
        end

        def argument_types
          Builder.ffi_function_argument_types info
        end

        def return_type
          Builder.ffi_function_return_type info
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gir_ffi-0.4.3 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.4.2 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.4.1 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.4.0 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.3.2 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.3.1 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.3.0 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.2.3 lib/gir_ffi/builder/type/callback.rb
gir_ffi-0.2.2 lib/gir_ffi/builder/type/callback.rb