Class: RbSDL2::RWObject::WriteCallback

Inherits:
FFI::Function
  • Object
show all
Defined in:
lib/rb_sdl2/rw_ops/rw_object.rb

Instance Method Summary collapse

Constructor Details

#initializeWriteCallback

Returns a new instance of WriteCallback.



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rb_sdl2/rw_ops/rw_object.rb', line 71

def initialize
  # size_t (* write) (struct RWops * context, const void *ptr, size_t size, size_t num);
  super(:size_t, [:pointer, :pointer, :size_t, :size_t]) do |_context, ptr, size, max_num|
    str = ptr.read_bytes(size * max_num)
    yield(str) / size
  rescue => e
    raise e if $DEBUG
    Error.last_error_message = e.message
    0
  end
end