Sha256: a292c9b8494841c1599069e292037aed2ac4464e315c9366a34370a887baebe0

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

class Plaything
  module OpenAL
    def self.TypeClass(type)
      Class.new do
        extend FFI::DataConverter
        @@type = type

        class << self
          def inherited(other)
            other.native_type(type)
          end

          def type
            @@type
          end

          def to_native(source, ctx)
            source.value
          end

          def from_native(value, ctx)
            new(value)
          end

          def size
            type.size
          end

          def extract(pointer, count)
            pointer.read_array_of_type(self, :read_uint, count).map do |uint|
              new(uint)
            end
          end
        end

        def initialize(value)
          @value = value
        end

        def ==(other)
          other.is_a?(self.class) and other.value == value
        end

        def to_native
          self.class.to_native(self, nil)
        end

        attr_reader :value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plaything-1.0.0 lib/plaything/support/type_class.rb