9 #include "sqstdstream.h" 10 #include "sqstdblobimpl.h" 12 #define SETUP_STREAM(v) \ 13 SQStream *self = NULL; \ 14 if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)SQSTD_STREAM_TYPE_TAG))) \ 15 return sq_throwerror(v,_SC("invalid type tag")); \ 16 if(!self->IsValid()) \ 17 return sq_throwerror(v,_SC("the stream is invalid")); 22 SQUserPointer data,blobp;
25 if(size > self->Len()) {
29 res =
self->Read(data,size);
33 memcpy(blobp,data,res);
37 #define SAFE_READN(ptr,len) { \ 38 if(self->Read(ptr,len) != len) return sq_throwerror(v,_SC("io error")); \ 108 if(self->Write(data,size) != size)
117 SQInteger format, ti;
125 self->Write(&i,
sizeof(SQInteger));
132 self->Write(&i,
sizeof(SQInt32));
139 self->Write(&s,
sizeof(
short));
145 w = (
unsigned short)ti;
146 self->Write(&w,
sizeof(
unsigned short));
153 self->Write(&c,
sizeof(
char));
159 b = (
unsigned char)ti;
160 self->Write(&b,
sizeof(
unsigned char));
167 self->Write(&f,
sizeof(
float));
174 self->Write(&d,
sizeof(
double));
186 SQInteger offset, origin = SQ_SEEK_SET;
192 case 'b': origin = SQ_SEEK_SET;
break;
193 case 'c': origin = SQ_SEEK_CUR;
break;
194 case 'e': origin = SQ_SEEK_END;
break;
237 _DECL_STREAM_FUNC(readblob,2,_SC(
"xn")),
238 _DECL_STREAM_FUNC(readn,2,_SC(
"xn")),
239 _DECL_STREAM_FUNC(writeblob,-2,_SC(
"xx")),
240 _DECL_STREAM_FUNC(writen,3,_SC(
"xnn")),
241 _DECL_STREAM_FUNC(seek,-2,_SC(
"xnn")),
242 _DECL_STREAM_FUNC(tell,1,_SC(
"x")),
243 _DECL_STREAM_FUNC(len,1,_SC(
"x")),
244 _DECL_STREAM_FUNC(eos,1,_SC(
"x")),
245 _DECL_STREAM_FUNC(flush,1,_SC(
"x")),
253 if(SQ_FAILED(
sq_get(v,-2))) {
280 SQRESULT
declare_stream(HSQUIRRELVM v,
const SQChar* name,SQUserPointer typetag,
const SQChar* reg_name,SQRegFunction *methods,SQRegFunction *globals)
290 if(SQ_SUCCEEDED(
sq_get(v,-3))) {
294 while(methods[i].name != 0) {
295 SQRegFunction &f = methods[i];
307 while(globals[i].name!=0)
309 SQRegFunction &f = globals[i];
SQRESULT sq_get(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_newclass(HSQUIRRELVM v, SQBool hasbase)
void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
SQInteger _stream_len(HSQUIRRELVM v)
#define SAFE_READN(ptr, len)
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
SQInteger _stream_writen(HSQUIRRELVM v)
SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size)
void sq_pushnull(HSQUIRRELVM v)
void sq_pushroottable(HSQUIRRELVM v)
void sq_pushregistrytable(HSQUIRRELVM v)
void sq_pushfloat(HSQUIRRELVM v, SQFloat n)
SQRESULT sq_getinteger(HSQUIRRELVM v, SQInteger idx, SQInteger *i)
void init_streamclass(HSQUIRRELVM v)
SQInteger sq_gettop(HSQUIRRELVM v)
void sq_pushinteger(HSQUIRRELVM v, SQInteger n)
void sq_newclosure(HSQUIRRELVM v, SQFUNCTION func, SQUnsignedInteger nfreevars)
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v, SQInteger idx, const SQChar *name)
void sq_settop(HSQUIRRELVM v, SQInteger newtop)
SQRESULT sq_getfloat(HSQUIRRELVM v, SQInteger idx, SQFloat *f)
SQInteger _stream_flush(HSQUIRRELVM v)
void sq_remove(HSQUIRRELVM v, SQInteger idx)
SQInteger _stream_writeblob(HSQUIRRELVM v)
SQRESULT sq_setparamscheck(HSQUIRRELVM v, SQInteger nparamscheck, const SQChar *typemask)
SQInteger sqstd_getblobsize(HSQUIRRELVM v, SQInteger idx)
void sq_pushstring(HSQUIRRELVM v, const SQChar *s, SQInteger len)
SQObjectType sq_gettype(HSQUIRRELVM v, SQInteger idx)
SQRESULT sqstd_getblob(HSQUIRRELVM v, SQInteger idx, SQUserPointer *ptr)
SQRESULT declare_stream(HSQUIRRELVM v, const SQChar *name, SQUserPointer typetag, const SQChar *reg_name, SQRegFunction *methods, SQRegFunction *globals)
SQInteger _stream_tell(HSQUIRRELVM v)
SQRESULT sq_settypetag(HSQUIRRELVM v, SQInteger idx, SQUserPointer typetag)
SQChar * sq_getscratchpad(HSQUIRRELVM v, SQInteger minsize)
SQInteger _stream_seek(HSQUIRRELVM v)
static SQRegFunction _stream_methods[]
SQInteger _stream_readblob(HSQUIRRELVM v)
SQInteger _stream_eos(HSQUIRRELVM v)
SQInteger _stream_readn(HSQUIRRELVM v)