Przeglądaj źródła

Changed the prototype of sq_tobool and added sq_tointeger, sq_tofloat.

mingodad 11 lat temu
rodzic
commit
1b2ea23e58

+ 3 - 1
SquiLu-ext/sqmodule.h

@@ -103,7 +103,9 @@ extern "C" {
 #else
         void            (*tostring)(HSQUIRRELVM v,SQInteger idx);
 #endif
-        void            (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
+        SQRESULT        (*tobool)(HSQUIRRELVM v, SQInteger idx);
+        SQRESULT        (*tointeger)(HSQUIRRELVM v, SQInteger idx);
+        SQRESULT        (*tofloat)(HSQUIRRELVM v, SQInteger idx);
         SQRESULT        (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
         SQRESULT        (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
         SQRESULT        (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);

+ 2 - 0
SquiLu-ext/sqratimport.cpp

@@ -101,6 +101,8 @@ static HSQAPI sqrat_newapi() {
     sq->instanceof = sq_instanceof;
     sq->tostring = sq_tostring;
     sq->tobool = sq_tobool;
+    sq->tointeger = sq_tointeger;
+    sq->tofloat = sq_tofloat;
     sq->getstring = sq_getstring;
     sq->getinteger = sq_getinteger;
     sq->getthread = sq_getthread;

+ 27 - 3
SquiLu/squirrel/sqapi.cpp

@@ -751,10 +751,34 @@ SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx)
 	return SQ_OK;
 }
 
-void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
+SQRESULT sq_tobool(HSQUIRRELVM v, SQInteger idx)
 {
-	SQObjectPtr &o = stack_get(v, idx);
-	*b = SQVM::IsFalse(o)?SQFalse:SQTrue;
+	SQObjectPtr res;
+	SQBool b;
+	SQ_RETURN_IF_ERROR(sq_getbool(v,idx, &b));
+	_integer(res) = b;
+	v->Push(res);
+	return SQ_OK;
+}
+
+SQRESULT sq_tointeger(HSQUIRRELVM v, SQInteger idx)
+{
+	SQObjectPtr res;
+	SQInteger i;
+	SQ_RETURN_IF_ERROR(sq_getinteger(v,idx, &i));
+	_integer(res) = i;
+	v->Push(res);
+	return SQ_OK;
+}
+
+SQRESULT sq_tofloat(HSQUIRRELVM v, SQInteger idx)
+{
+	SQObjectPtr res;
+	SQFloat f;
+	SQ_RETURN_IF_ERROR(sq_getfloat(v,idx, &f));
+	_float(res) = f;
+	v->Push(res);
+	return SQ_OK;
 }
 
 SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i)

+ 2 - 2
SquiLu/squirrel/sqbaselib.cpp

@@ -2157,7 +2157,7 @@ static SQRESULT class_newmember(HSQUIRRELVM v)
 	SQBool bstatic = SQFalse;
 	if(top == 5)
 	{
-		sq_tobool(v,-1,&bstatic);
+		sq_getbool(v,-1,&bstatic);
 		sq_pop(v,1);
 	}
 
@@ -2173,7 +2173,7 @@ static SQRESULT class_rawnewmember(HSQUIRRELVM v)
 	SQBool bstatic = SQFalse;
 	if(top == 5)
 	{
-		sq_tobool(v,-1,&bstatic);
+		sq_getbool(v,-1,&bstatic);
 		sq_pop(v,1);
 	}