-
Notifications
You must be signed in to change notification settings - Fork 74
Sdl RWCreate
Tangent 128 edited this page Mar 28, 2015
·
3 revisions
- SDL.RWCreate
- Function
- SYNOPSIS
- ARGUMENTS
- RETURNS
- Table description
- Size
- Returns
- Seek
- Arguments
- Returns
- Read
- Arguments
- Returns
- Write
- Arguments
- Returns
- Close
- Size
- EXAMPLE
- Function
Create a custom RWops object.
rw, err = function SDL.RWCreate(funcs)
- funcs, the table with the functions (see Table description).
- rw, the RWops object or nil
- err, the error message
function size()
The size of the stream
function seek(offset, whence)
- offset, the offset count
- whence, type of seek
The seek
function read(n, size)
- n, the number to read
- size, each block to read
- The string read
- The number of bytes read
function write(data, n, size)
- data, the data string
- n, the number to write
- size, each block to write
- The number of bytes written
function close()
local SDL = require "SDL"
-- The table for RW ops
local reader = { }
function reader.size()
return -1
end
function reader.read(n, size)
local r = reader.file:read(n * size)
if not r then
return nil, 0
end
return r, #r
end
function reader.write(data, n, size)
local r = reader.file:write(data)
if not r then
return 0
end
return n * size
end
function reader.seek(offset, whence)
local v = nil
if whence == SDL.rwopsSeek.Set then
v = "set"
elseif whence == SDL.rwopsSeek.Current then
v = "cur"
elseif whence == SDL.rwopsSeek.End then
v = "end"
end
if not v then
error("unknown whence")
end
local r = reader.file:seek(v, offset)
if not r then
return 0
end
return r
end
function reader.close()
reader.file:close()
end
reader.file = io.open("mario.png", "r")
if not reader.file then
-- Handle your error here
error("Failed to load")
end
local rw = SDL.RWCreate(reader)