class SDL2::RWops

NOTE: This is just a forward declaration for the callbacks

“This is the read/write operation structure – very basic”

size    - " Return the size of the file in this rwops, or -1 if unkown
seek    - "Seek to \c offset relative to \c whence, one of stdio's whence values:
            RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
            return the final offset in the data stream, or -1 on error.
read    - "Read up to \c maxnum objects each of size \c size from the data
            stream to the area pointed at by \c ptr.
            Return the number of objects read, or 0 at error or end of file.
write   - "Write eactly \c num objects each of size \c size from the area
            pointed at by \c ptr to data stream.
            Return the number of objects written, or 0 at error or end of file.
close   - "Close and free an allocated SDL_RWops structure.
            Return 0 if successful or -1 on write error when flushing data.

Constants

SEEK_CUR

“Seek relative to current read point”

SEEK_END

“Seek relative to the end of data”

SEEK_SET

“Seek from the beginning of data”

Public Class Methods

from_file(file_name, mode) click to toggle source

Create RWOps from file name

# File lib/sdl2/rwops.rb, line 109
def self.from_file(file_name, mode)
  SDL2.rw_from_file!(file_name, mode)
end
release(pointer) click to toggle source

Release this structure using SDL_FreeRW

# File lib/sdl2/rwops.rb, line 93
def self.release(pointer)
  SDL2.free_rw(pointer)
end

Public Instance Methods

close() click to toggle source

“Close and free an allocated SDL_RWops structure.”

"\return 0 if successful or -1 on write error when flushing data."
# File lib/sdl2/rwops.rb, line 155
def close
  self[:close].call(self)
end
read(pointer, size, n) click to toggle source

“Read up to c maxnum objects each of size c size from the data

stream to the area pointed at by \c ptr."
"\return the number of objects read, or 0 at error or end of file."
# File lib/sdl2/rwops.rb, line 139
def read(pointer, size, n)
  self[:read].call(self, pointer, size, n)
end
seek(offset, whence) click to toggle source

“Seek to c offset in the data stream, or -1 on error.” “return the number of objects read, or 0 at error or end of file”

# File lib/sdl2/rwops.rb, line 124
def seek(offset, whence)
  self[:seek].call(self, offset, whence)
end
size() click to toggle source

“Return the size of the file in this rwops, or -1 if unkown”

# File lib/sdl2/rwops.rb, line 117
def size
  self[:size].call
end
tell() click to toggle source

BadQuanta: “I suppose this returns the current position” SDL_rwops.h:186.

# File lib/sdl2/rwops.rb, line 131
def tell
  self[:seek].call(self, 0, SEEK_CUR)
end
write(pointer, size, n) click to toggle source

“Write exactly c num objects each of size c size from the area pointed at by c ptr to data stream.”

“return the number of objects written, or 0 at error or end of file.”

# File lib/sdl2/rwops.rb, line 148
def write(pointer, size, n)
  self[:write].call(self, pointer, size, n)
end