Class: RbSDL2::RWOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/rb_sdl2/rw_ops/rw_operator.rb

Defined Under Namespace

Classes: CloseCallback, RWopsPointer, ReadCallback, SeekCallback, SizeCallback, WriteCallback

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, obj) ⇒ RWOperator

Returns a new instance of RWOperator.



87
88
89
90
91
92
93
94
95
96
# File 'lib/rb_sdl2/rw_ops/rw_operator.rb', line 87

def initialize(ptr, obj)
  st = ::SDL2::SDL_RWops.new(ptr)
  st[:close] = @close = CloseCallback.new(obj)
  st[:read]  = @read  = ReadCallback.new(obj)
  st[:seek]  = @seek  = SeekCallback.new(obj)
  st[:size]  = @size  = SizeCallback.new(obj)
  st[:write] = @write = WriteCallback.new(obj)
  @obj = obj
  @ptr = ptr
end

Class Method Details

.new(io) ⇒ Object

obj は Ruby IO と同じようにふるまうことを期待している。obj に対して close, seek, size, read, write のメソッドを呼び出す。メソッドの呼び出し引数は Ruby IO と同様である。メソッドの戻り値は Ruby IO と同じ値を返せばよい。メソッド内での例外は SDL のエラーに変換され、Ruby 側には反映されない。obj がメソッド呼び出しに応答しない場合も安全である。その場合は SDL 側にエラーが通知される。

Raises:



80
81
82
83
84
# File 'lib/rb_sdl2/rw_ops/rw_operator.rb', line 80

def new(io)
  ptr = RWopsPointer.new(::SDL2.SDL_AllocRW)
  raise RbSDL2Error if ptr.null?
  super(ptr, io)
end

Instance Method Details

#__getobj__Object



98
# File 'lib/rb_sdl2/rw_ops/rw_operator.rb', line 98

def __getobj__ = @obj

#to_ptrObject



100
# File 'lib/rb_sdl2/rw_ops/rw_operator.rb', line 100

def to_ptr = @ptr