Class: RbSDL2::RWObject::ReadCallback
- Inherits:
-
FFI::Function
- Object
- FFI::Function
- RbSDL2::RWObject::ReadCallback
- Defined in:
- lib/rb_sdl2/rw_ops/rw_object.rb
Instance Method Summary collapse
-
#initialize ⇒ ReadCallback
constructor
A new instance of ReadCallback.
Constructor Details
#initialize ⇒ ReadCallback
Returns a new instance of ReadCallback.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rb_sdl2/rw_ops/rw_object.rb', line 21 def initialize # size_t (* read) (struct RWops * context, void *ptr, size_t size, size_t maxnum); super(:size_t, [:pointer, :pointer, :size_t, :size_t]) do |_context, ptr, size, max_num| num = size * max_num str = yield(num) next 0 if str.nil? # EOF len = str.size if len > num # 要求より多い文字数を返している。obj.read が壊れている。 raise RbSDL2Error, "The return value of read method is corrupted" end ptr.write_bytes(str, 0, len) len / size rescue => e raise e if $DEBUG Error. = e. 0 end end |