Sha256: e6ff855c8d1c3d003d199483472e3c8e51d50c40d7efb8e6787a29e91425a24a

Contents?: true

Size: 656 Bytes

Versions: 3

Compression:

Stored size: 656 Bytes

Contents

# frozen_string_literal: true
module GirFFI
  module FFIExt
    # Extensions to FFI::Pointer
    module Pointer
      def to_ptr
        self
      end

      def to_value
        self
      end

      def zero?
        null?
      end

      # FIXME: Should probably not be here.
      def to_object
        return nil if null?
        gtype = GObject.type_from_instance_pointer self
        Builder.build_by_gtype(gtype).direct_wrap self
      end

      def to_utf8
        null? ? nil : read_string.force_encoding('utf-8')
      end
    end
  end
end

# TODO: Move use to InPointer and InOutPointer?
FFI::Pointer.send :include, GirFFI::FFIExt::Pointer

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gir_ffi-0.9.5 lib/gir_ffi/ffi_ext/pointer.rb
gir_ffi-0.9.4 lib/gir_ffi/ffi_ext/pointer.rb
gir_ffi-0.9.3 lib/gir_ffi/ffi_ext/pointer.rb