author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 26 Sep 2004 13:17:54 +0000 | |
changeset 654 | c0ae01de361d |
parent 514 | f4e89d934fee |
permissions | -rw-r--r-- |
514
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* SDL_RWops - ruby interface |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Author:: Ed Sinjiashvili (slimb@vlinkmail.com) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* License:: LGPL |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
#include "SDL_rwops.h" |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
#include "ruby.h" |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include "rb_physfs.h" |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
#include "rb_sdl_rwops.h" |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
VALUE classRWops; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
* RWops constructor |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
VALUE sdl_rwops_new (SDL_RWops *ops) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
VALUE result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
if (ops == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
result = Data_Wrap_Struct (classRWops, 0, SDL_FreeRW, ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
return result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
* PhysicsFS::RWops::from_file name, mode |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
* create RWops object from file |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
VALUE sdl_rwops_from_file (VALUE self, VALUE name, VALUE mode) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
SDL_RWops *ops = SDL_RWFromFile(STR2CSTR(name), STR2CSTR(mode)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
return sdl_rwops_new (ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
* PhysicsFS::RWops::from_memory string |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
* create RWops object from memory |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
VALUE sdl_rwops_from_mem (VALUE self, VALUE str) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
int len = RSTRING(str)->len; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
void *mem = STR2CSTR(str); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
SDL_RWops *ops = SDL_RWFromMem(mem, len); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
return sdl_rwops_new (ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
* PhysicsFS::RWops#seek offset, whence |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
* position RWops object |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
VALUE sdl_rwops_seek (VALUE self, VALUE offset, VALUE whence) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
int result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
SDL_RWops *ops; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
Data_Get_Struct (self, SDL_RWops, ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
if (ops == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
result = SDL_RWseek(ops, FIX2INT(offset), FIX2INT(whence)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
return INT2FIX(result); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
* PhysicsFS::RWops#close |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
* close RWops. No use of the object is possible after that. |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
VALUE sdl_rwops_close (VALUE self) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
int result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
SDL_RWops *ops; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
Data_Get_Struct (self, SDL_RWops, ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
if (ops == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
result = SDL_RWclose (ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
DATA_PTR(self) = 0; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
return INT2FIX(result); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
* PhysicsFS::RWops#read |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
* read from RWops object objCount objSize'd entities. |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
* return string containing raw data or nil |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
VALUE sdl_rwops_read (VALUE self, VALUE objSize, VALUE objCount) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
int objRead; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
void *buffer; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
VALUE result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
SDL_RWops *ops; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
Data_Get_Struct (self, SDL_RWops, ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
if (ops == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
buffer = malloc (FIX2UINT(objSize) * FIX2UINT(objCount)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
if (buffer == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
objRead = SDL_RWread (ops, buffer, FIX2UINT(objSize), FIX2UINT(objCount)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
if (objRead == -1) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
free (buffer); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
result = rb_str_new (buffer, objRead * FIX2UINT(objSize)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
free (buffer); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
return result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
/* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
* PhysicsFS::RWops#write buffer, size, n |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
* |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
* write raw string containing n objects size length each. |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
* return number of objects written or nil |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
*/ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
VALUE sdl_rwops_write (VALUE self, VALUE buffer, VALUE size, VALUE n) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
int result; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
SDL_RWops *ops; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
Data_Get_Struct (self, SDL_RWops, ops); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
if (ops == 0) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
result = SDL_RWwrite (ops, STR2CSTR(buffer), FIX2INT(size), FIX2INT(n)); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
if (result == -1) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
return Qnil; |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
return INT2FIX(result); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
} |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
void init_sdl_rwops (void) |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
{ |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
classRWops = rb_define_class_under (modulePhysfs, "RWops", rb_cObject); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
rb_define_method (classRWops, "seek", sdl_rwops_seek, 2); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
rb_define_method (classRWops, "read", sdl_rwops_read, 2); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
rb_define_method (classRWops, "write", sdl_rwops_write, 3); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
rb_define_method (classRWops, "close", sdl_rwops_close, 0); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
|
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
rb_define_singleton_method (classRWops, "from_file", |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
sdl_rwops_from_file, 2); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
rb_define_singleton_method (classRWops, "from_memory", |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
sdl_rwops_from_mem, 1); |
f4e89d934fee
Initial import of Ruby bindings for PhysicsFS.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
} |