4 #include "sqpcheader.h" 7 #include "sqfuncproto.h" 13 SQInteger cssize = v->_callsstacksize;
15 SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
16 if(sq_isclosure(ci._closure)) {
17 SQClosure *c = _closure(ci._closure);
18 SQFunctionProto *proto = _funcproto(c->_function);
20 fi->name = type(proto->_name) == OT_STRING?_stringval(proto->_name):_SC(
"unknown");
21 fi->source = type(proto->_name) == OT_STRING?_stringval(proto->_sourcename):_SC(
"unknown");
28 SQRESULT
sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
30 SQInteger cssize = v->_callsstacksize;
32 memset(si, 0,
sizeof(SQStackInfos));
33 SQVM::CallInfo &ci = v->_callsstack[cssize-level-1];
34 switch (type(ci._closure)) {
36 SQFunctionProto *func = _funcproto(_closure(ci._closure)->_function);
37 if (type(func->_name) == OT_STRING)
38 si->funcname = _stringval(func->_name);
39 if (type(func->_sourcename) == OT_STRING)
40 si->source = _stringval(func->_sourcename);
41 si->line = func->GetLine(ci._ip);
44 case OT_NATIVECLOSURE:
45 si->source = _SC(
"NATIVE");
46 si->funcname = _SC(
"unknown");
47 if(type(_nativeclosure(ci._closure)->_name) == OT_STRING)
48 si->funcname = _stringval(_nativeclosure(ci._closure)->_name);
58 void SQVM::Raise_Error(
const SQChar *s, ...)
62 scvsprintf(_sp(rsl((SQInteger)scstrlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
64 _lasterror = SQString::Create(_ss(
this),_spval,-1);
67 void SQVM::Raise_Error(SQObjectPtr &desc)
72 SQString *SQVM::PrintObjVal(
const SQObject &o)
75 case OT_STRING:
return _string(o);
79 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC(
"%I64d"), _integer(o));
82 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC(
"%ld"), _integer(o));
84 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC(
"%d"), _integer(o));
86 return SQString::Create(_ss(
this), _spval);
89 scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC(
"%.14g"), _float(o));
90 return SQString::Create(_ss(
this), _spval);
97 void SQVM::Raise_IdxError(SQObject &o)
99 SQObjectPtr oval = PrintObjVal(o);
100 Raise_Error(_SC(
"the index '%.50s' does not exist"), _stringval(oval));
103 void SQVM::Raise_CompareError(
const SQObject &o1,
const SQObject &o2)
105 SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
106 Raise_Error(_SC(
"comparsion between '%.50s' and '%.50s'"), _stringval(oval1), _stringval(oval2));
110 void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger type)
112 SQObjectPtr exptypes = SQString::Create(_ss(
this), _SC(
""), -1);
114 for(SQInteger i=0; i<16; i++)
116 SQInteger mask = 0x00000001 << i;
117 if(typemask & (mask)) {
118 if(found>0) StringCat(exptypes,SQString::Create(_ss(
this), _SC(
"|"), -1), exptypes);
120 StringCat(exptypes,SQString::Create(_ss(
this),
IdType2Name((SQObjectType)mask), -1), exptypes);
123 Raise_Error(_SC(
"parameter %d has an invalid type '%s' ; expected: '%s'"), nparam,
IdType2Name((SQObjectType)type), _stringval(exptypes));
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
const SQChar * GetTypeName(const SQObjectPtr &obj1)
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v, SQInteger level, SQFunctionInfo *fi)
const SQChar * IdType2Name(SQObjectType type)
SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)