2 see copyright notice in squirrel.h
4 #include "sqpcheader.h"
7 #include "sqfuncproto.h"
11 SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
13 SQInteger cssize = v->_callsstacksize;
15 memset(si, 0, sizeof(SQStackInfos));
16 SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
17 switch (type(ci._closure)) {
19 SQFunctionProto *func = _funcproto(_closure(ci._closure)->_function);
20 if (type(func->_name) == OT_STRING)
21 si->funcname = _stringval(func->_name);
22 if (type(func->_sourcename) == OT_STRING)
23 si->source = _stringval(func->_sourcename);
24 si->line = func->GetLine(ci._ip);
27 case OT_NATIVECLOSURE:
28 si->source = _SC("NATIVE");
29 si->funcname = _SC("unknown");
30 if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
31 si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
34 default: break; //shutup compiler
41 void SQVM::Raise_Error(const SQChar *s, ...)
45 scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
47 _lasterror = SQString::Create(_ss(this),_spval,-1);
50 void SQVM::Raise_Error(SQObjectPtr &desc)
55 SQString *SQVM::PrintObjVal(const SQObject &o)
58 case OT_STRING: return _string(o);
60 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
61 return SQString::Create(_ss(this), _spval);
64 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%.14g"), _float(o));
65 return SQString::Create(_ss(this), _spval);
68 return SQString::Create(_ss(this), GetTypeName(o));
72 void SQVM::Raise_IdxError(SQObject &o)
74 SQObjectPtr oval = PrintObjVal(o);
75 Raise_Error(_SC("the index '%.50s' does not exist"), _stringval(oval));
78 void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
80 SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
81 Raise_Error(_SC("comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2));
85 void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
87 SQObjectPtr exptypes = SQString::Create(_ss(this), _SC(""), -1);
89 for(SQInteger i=0; i<16; i++)
91 SQInteger mask = 0x00000001 << i;
92 if(typemask & (mask)) {
93 if(found>0) StringCat(exptypes,SQString::Create(_ss(this), _SC("|"), -1), exptypes);
95 StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes);
98 Raise_Error(_SC("parameter %d has an invalid type '%s' ; expected: '%s'"), nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));