class RbSDL2::RWOperator::ReadCallback

Public Class Methods

new(obj) click to toggle source
Calls superclass method
# File lib/rb_sdl2/rw_ops/rw_operator.rb, line 20
def initialize(obj)
  # size_t (* read) (struct SDL_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|
    return 0 if ptr.null?
    max = size * max_num
    str = obj.read(max)
    len = str.size
    # len > max は obj.read が壊れている。
    return 0 if str.nil? || len > max
    ptr.write_bytes(str, 0, len)
    len / size
  rescue
    0
  end
end