Przeglądaj źródła

Changed sq_throwerror to work like printf.

mingodad 13 lat temu
rodzic
commit
cf8faa108a
2 zmienionych plików z 14 dodań i 2 usunięć
  1. 7 1
      include/squirrel.h
  2. 7 1
      squirrel/sqapi.cpp

+ 7 - 1
include/squirrel.h

@@ -125,6 +125,7 @@ typedef wchar_t SQChar;
 #define _SC(a) L##a
 #define _SC(a) L##a
 #define	scstrcmp	wcscmp
 #define	scstrcmp	wcscmp
 #define scsprintf	swprintf
 #define scsprintf	swprintf
+#define scsnprintf	swnprintf
 #define scstrlen	wcslen
 #define scstrlen	wcslen
 #define scstrtod	wcstod
 #define scstrtod	wcstod
 #ifdef _SQ64
 #ifdef _SQ64
@@ -134,7 +135,9 @@ typedef wchar_t SQChar;
 #endif
 #endif
 #define scatoi		_wtoi
 #define scatoi		_wtoi
 #define scstrtoul	wcstoul
 #define scstrtoul	wcstoul
+#define scvfprintf	vfwprintf
 #define scvsprintf	vswprintf
 #define scvsprintf	vswprintf
+#define scvsnprintf	vswnprintf
 #define scstrstr	wcsstr
 #define scstrstr	wcsstr
 #define scisspace	iswspace
 #define scisspace	iswspace
 #define scisdigit	iswdigit
 #define scisdigit	iswdigit
@@ -149,6 +152,7 @@ typedef char SQChar;
 #define _SC(a) a
 #define _SC(a) a
 #define	scstrcmp	strcmp
 #define	scstrcmp	strcmp
 #define scsprintf	sprintf
 #define scsprintf	sprintf
+#define scsnprintf	snprintf
 #define scstrlen	strlen
 #define scstrlen	strlen
 #define scstrtod	strtod
 #define scstrtod	strtod
 #ifdef _SQ64
 #ifdef _SQ64
@@ -162,7 +166,9 @@ typedef char SQChar;
 #endif
 #endif
 #define scatoi		atoi
 #define scatoi		atoi
 #define scstrtoul	strtoul
 #define scstrtoul	strtoul
+#define scvfprintf	vfprintf
 #define scvsprintf	vsprintf
 #define scvsprintf	vsprintf
+#define scvsnprintf	vsnprintf
 #define scstrstr	strstr
 #define scstrstr	strstr
 #define scisspace	isspace
 #define scisspace	isspace
 #define scisdigit	isdigit
 #define scisdigit	isdigit
@@ -432,7 +438,7 @@ SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
 SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
 SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
 SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v);
 SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v);
 SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
 SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
-SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
+SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *fmt, ...);
 SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
 SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
 SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
 SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
 SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
 SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);

+ 7 - 1
squirrel/sqapi.cpp

@@ -12,6 +12,7 @@
 #include "sqcompiler.h"
 #include "sqcompiler.h"
 #include "sqfuncstate.h"
 #include "sqfuncstate.h"
 #include "sqclass.h"
 #include "sqclass.h"
+#include <stdarg.h>
 
 
 bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
 bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
 {
 {
@@ -1032,8 +1033,13 @@ void sq_resetobject(HSQOBJECT *po)
 	po->_unVal.pUserPointer=NULL;po->_type=OT_NULL;
 	po->_unVal.pUserPointer=NULL;po->_type=OT_NULL;
 }
 }
 
 
-SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err)
+SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *fmt, ...)
 {
 {
+    static SQChar err[256];
+    va_list vl;
+    va_start(vl, fmt);
+    scvsnprintf(err, sizeof(err), fmt, vl);
+    va_end(vl);
 	v->_lasterror=SQString::Create(_ss(v),err);
 	v->_lasterror=SQString::Create(_ss(v),err);
 	return SQ_ERROR;
 	return SQ_ERROR;
 }
 }