Sha256: 8dad291df5fa1fbaccd8e9216d4d841d2280ae06741def5150d6dc92c16eaf4b

Contents?: true

Size: 656 Bytes

Versions: 1

Compression:

Stored size: 656 Bytes

Contents

require 'ffi'

module PyBind
  class PyObjectStruct < FFI::Struct
    layout ob_refcnt: :ssize_t,
           ob_type:   PyObjectStruct.by_ref

    def self.null
      new(FFI::Pointer::NULL)
    end

    def none?
      PyBind.None.to_ptr == to_ptr
    end

    def kind_of?(klass)
      case klass
      when PyBind::PyObjectStruct
        value = LibPython.PyObject_IsInstance(self, klass)
        raise PyError.fetch if value == -1
        value == 1
      else
        super
      end
    end

    def to_ruby_object
      PyObject.new(self)
    end

    def to_python_struct
      self
    end
    alias_method :to_python, :to_python_struct
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pybind-0.1.0 lib/pybind/struct.rb