#define SETUP_BLOB(v) \
SQBlob *self = NULL; \
- { if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,SQSTD_BLOB_TYPE_TAG))) \
+ { if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)SQSTD_BLOB_TYPE_TAG))) \
return SQ_ERROR; }
-static int _blob_resize(HSQUIRRELVM v)
+static SQInteger _blob_resize(HSQUIRRELVM v)
{
SETUP_BLOB(v);
SQInteger size;
*n=(unsigned short)((*n>>8)&0x00FF)| ((*n<<8)&0xFF00);
}
-static int _blob_swap4(HSQUIRRELVM v)
+static SQInteger _blob_swap4(HSQUIRRELVM v)
{
SETUP_BLOB(v);
- int num=(self->Len()-(self->Len()%4))>>2;
+ SQInteger num=(self->Len()-(self->Len()%4))>>2;
unsigned int *t=(unsigned int *)self->GetBuf();
- for(int i = 0; i < num; i++) {
+ for(SQInteger i = 0; i < num; i++) {
__swap_dword(&t[i]);
}
return 0;
}
-static int _blob_swap2(HSQUIRRELVM v)
+static SQInteger _blob_swap2(HSQUIRRELVM v)
{
SETUP_BLOB(v);
- int num=(self->Len()-(self->Len()%2))>>1;
+ SQInteger num=(self->Len()-(self->Len()%2))>>1;
unsigned short *t = (unsigned short *)self->GetBuf();
- for(int i = 0; i < num; i++) {
+ for(SQInteger i = 0; i < num; i++) {
__swap_word(&t[i]);
}
return 0;
}
-static int _blob__set(HSQUIRRELVM v)
+static SQInteger _blob__set(HSQUIRRELVM v)
{
SETUP_BLOB(v);
SQInteger idx,val;
return 1;
}
-static int _blob__get(HSQUIRRELVM v)
+static SQInteger _blob__get(HSQUIRRELVM v)
{
SETUP_BLOB(v);
SQInteger idx;
return 1;
}
-static int _blob__nexti(HSQUIRRELVM v)
+static SQInteger _blob__nexti(HSQUIRRELVM v)
{
SETUP_BLOB(v);
if(sq_gettype(v,2) == OT_NULL) {
return sq_throwerror(v,_SC("internal error (_nexti) wrong argument type"));
}
-static int _blob__typeof(HSQUIRRELVM v)
+static SQInteger _blob__typeof(HSQUIRRELVM v)
{
sq_pushstring(v,_SC("blob"),-1);
return 1;
}
-static int _blob_releasehook(SQUserPointer p, int size)
+static SQInteger _blob_releasehook(SQUserPointer p, SQInteger size)
{
SQBlob *self = (SQBlob*)p;
delete self;
return 1;
}
-static int _blob_constructor(HSQUIRRELVM v)
+static SQInteger _blob_constructor(HSQUIRRELVM v)
{
SQInteger nparam = sq_gettop(v);
SQInteger size = 0;
//GLOBAL FUNCTIONS
-static int _g_blob_casti2f(HSQUIRRELVM v)
+static SQInteger _g_blob_casti2f(HSQUIRRELVM v)
{
SQInteger i;
sq_getinteger(v,2,&i);
return 1;
}
-static int _g_blob_castf2i(HSQUIRRELVM v)
+static SQInteger _g_blob_castf2i(HSQUIRRELVM v)
{
SQFloat f;
sq_getfloat(v,2,&f);
return 1;
}
-static int _g_blob_swap2(HSQUIRRELVM v)
+static SQInteger _g_blob_swap2(HSQUIRRELVM v)
{
SQInteger i;
sq_getinteger(v,2,&i);
return 1;
}
-static int _g_blob_swap4(HSQUIRRELVM v)
+static SQInteger _g_blob_swap4(HSQUIRRELVM v)
{
SQInteger i;
sq_getinteger(v,2,&i);
- __swap_dword((unsigned int *)&i);
- sq_pushinteger(v,i);
+ unsigned int t4 = (unsigned int)i;
+ __swap_dword(&t4);
+ sq_pushinteger(v,(SQInteger)t4);
return 1;
}
-static int _g_blob_swapfloat(HSQUIRRELVM v)
+static SQInteger _g_blob_swapfloat(HSQUIRRELVM v)
{
SQFloat f;
sq_getfloat(v,2,&f);
{0,0}
};
-SQRESULT sqstd_getblob(HSQUIRRELVM v,int idx,SQUserPointer *ptr)
+SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr)
{
SQBlob *blob;
- if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,SQSTD_BLOB_TYPE_TAG)))
+ if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG)))
return -1;
*ptr = blob->GetBuf();
return SQ_OK;
}
-int sqstd_getblobsize(HSQUIRRELVM v,int idx)
+SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx)
{
SQBlob *blob;
- if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,SQSTD_BLOB_TYPE_TAG)))
+ if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG)))
return -1;
return blob->Len();
}
-SQUserPointer sqstd_createblob(HSQUIRRELVM v, int size)
+SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size)
{
- int top = sq_gettop(v);
-// SQUserPointer p = sq_newuserdata(v, sizeof(SQBlob));
-// sq_setreleasehook(v,-1,_blob_releasehook);
-// sq_settypetag(v,-1,SQSTD_BLOB_TYPE_TAG);
-// new (p) SQBlob(size);
+ SQInteger top = sq_gettop(v);
sq_pushregistrytable(v);
sq_pushstring(v,_SC("std_blob"),-1);
if(SQ_SUCCEEDED(sq_get(v,-2))) {
sq_push(v,1); // push the this
sq_pushinteger(v,size); //size
SQBlob *blob = NULL;
- if(SQ_SUCCEEDED(sq_call(v,2,SQTrue))
- && SQ_SUCCEEDED(sq_getinstanceup(v,-1,(SQUserPointer *)&blob,SQSTD_BLOB_TYPE_TAG))) {
- sq_remove(v,-2);
+ if(SQ_SUCCEEDED(sq_call(v,2,SQTrue,SQFalse))
+ && SQ_SUCCEEDED(sq_getinstanceup(v,-1,(SQUserPointer *)&blob,(SQUserPointer)SQSTD_BLOB_TYPE_TAG))) {
sq_remove(v,-2);
return blob->GetBuf();
}
SQRESULT sqstd_register_bloblib(HSQUIRRELVM v)
{
- return declare_stream(v,_SC("blob"),SQSTD_BLOB_TYPE_TAG,_SC("std_blob"),_blob_methods,bloblib_funcs);
+ return declare_stream(v,_SC("blob"),(SQUserPointer)SQSTD_BLOB_TYPE_TAG,_SC("std_blob"),_blob_methods,bloblib_funcs);
}