Просмотр исходного кода

Add new api to push lasterror_stackinfo.
Add new var to SQVM to store the stackinfo for the last error.
Add script function "get_last_stackinfo" to allow scripts get this information.

mingodad 13 лет назад
Родитель
Сommit
6292263419
6 измененных файлов с 30 добавлено и 5 удалено
  1. 1 0
      include/squirrel.h
  2. 14 0
      squirrel/sqapi.cpp
  3. 7 0
      squirrel/sqbaselib.cpp
  4. 3 3
      squirrel/sqdebug.cpp
  5. 4 2
      squirrel/sqvm.cpp
  6. 1 0
      squirrel/sqvm.h

+ 1 - 0
include/squirrel.h

@@ -508,6 +508,7 @@ SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
 SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
 SQUIRREL_API SQInteger sq_getfulltop(HSQUIRRELVM v);
 SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
+SQUIRREL_API void sq_getlaststackinfo(HSQUIRRELVM v);
 
 /*UTILITY MACRO*/
 #define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)

+ 14 - 0
squirrel/sqapi.cpp

@@ -1211,6 +1211,20 @@ void sq_getlasterror(HSQUIRRELVM v)
 {
 	v->Push(v->_lasterror);
 }
+
+void sq_getlaststackinfo(HSQUIRRELVM v)
+{
+    sq_newtable(v);
+    sq_pushliteral(v, _SC("line"));
+    sq_pushinteger(v, v->_lasterror_stackinfo.line);
+    sq_rawset(v, -3);
+    sq_pushliteral(v, _SC("source"));
+    sq_pushstring(v, v->_lasterror_stackinfo.source, -1);
+    sq_rawset(v, -3);
+    sq_pushliteral(v, _SC("funcname"));
+    sq_pushstring(v, v->_lasterror_stackinfo.funcname, -1);
+    sq_rawset(v, -3);
+}
 
 const SQChar *sq_getlasterror_str(HSQUIRRELVM v)
 {

+ 7 - 0
squirrel/sqbaselib.cpp

@@ -229,6 +229,12 @@ static SQInteger base_get_last_error(HSQUIRRELVM v)
     sq_getlasterror(v);
 	return 1;
 }
+
+static SQInteger base_get_last_stackinfo(HSQUIRRELVM v)
+{
+    sq_getlaststackinfo(v);
+	return 1;
+}
 
 static SQInteger base_compilestring(HSQUIRRELVM v)
 {
@@ -326,6 +332,7 @@ static SQRegFunction base_funcs[]={
 	{_SC("print"),base_print,-2, NULL},
 	{_SC("error"),base_error,2, NULL},
 	{_SC("get_last_error"),base_get_last_error,1, NULL},
+	{_SC("get_last_stackinfo"),base_get_last_stackinfo,1, NULL},
 	{_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
 	{_SC("newthread"),base_newthread,2, _SC(".c")},
 	{_SC("suspend"),base_suspend,-1, NULL},

+ 3 - 3
squirrel/sqdebug.cpp

@@ -61,12 +61,12 @@ void SQVM::Raise_Error(const SQChar *s, ...)
 	va_start(vl, s);
 	scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
 	va_end(vl);
-	_lasterror = SQString::Create(_ss(this),_spval,-1);
+	_lasterror = SQString::Create(_ss(this),_spval,-1);
 }
 
 void SQVM::Raise_Error(const SQObjectPtr &desc)
 {
-	_lasterror = desc;
+	_lasterror = desc;
 }
 
 SQString *SQVM::PrintObjVal(const SQObjectPtr &o)
@@ -102,7 +102,7 @@ void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
 void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
 {
 	SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1);
-	SQInteger found = 0;	
+	SQInteger found = 0;
 	for(SQInteger i=0; i<16; i++)
 	{
 		SQInteger mask = 0x00000001 << i;

+ 4 - 2
squirrel/sqvm.cpp

@@ -113,7 +113,8 @@ SQVM::SQVM(SQSharedState *ss)
 	_foreignptr = NULL;
 	_nnativecalls = 0;
 	_nmetamethodscall = 0;
-	_lasterror.Null();
+	_lasterror.Null();
+	memset(&_lasterror_stackinfo, 0, sizeof(SQStackInfos));
 	_errorhandler.Null();
 	_debughook = false;
 	_debughook_native = NULL;
@@ -1050,7 +1051,8 @@ exception_restore:
 		}
 	}
 exception_trap:
-	{
+	{
+	    sq_stackinfos(this, 0, &_lasterror_stackinfo);
 		SQObjectPtr currerror = _lasterror;
 //		dumpstack(_stackbase);
 //		SQInteger n = 0;

+ 1 - 0
squirrel/sqvm.h

@@ -150,6 +150,7 @@ public:
 	SQOuter	*_openouters;
 	SQObjectPtr _roottable;
 	SQObjectPtr _lasterror;
+	SQStackInfos _lasterror_stackinfo;
 	SQObjectPtr _errorhandler;
 
 	bool _debughook;