Code::Blocks  SVN r11506
sqstdaux.cpp
Go to the documentation of this file.
1 /* see copyright notice in squirrel.h */
2 #include <squirrel.h>
3 #include <sqstdaux.h>
4 #include <assert.h>
5 
6 void sqstd_printcallstack(HSQUIRRELVM v)
7 {
8  SQPRINTFUNCTION pf = sq_getprintfunc(v);
9  if(pf) {
10  SQStackInfos si;
11  SQInteger i;
12  SQBool b;
13  SQFloat f;
14  const SQChar *s;
15  SQInteger level=1; //1 is to skip this function that is level 0
16  const SQChar *name=0;
17  SQInteger seq=0;
18  pf(v,_SC("\nCALLSTACK\n"));
19  while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
20  {
21  const SQChar *fn=_SC("unknown");
22  const SQChar *src=_SC("unknown");
23  if(si.funcname)fn=si.funcname;
24  if(si.source)src=si.source;
25  pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line);
26  level++;
27  }
28  level=0;
29  pf(v,_SC("\nLOCALS\n"));
30 
31  for(level=0;level<10;level++){
32  seq=0;
33  while((name = sq_getlocal(v,level,seq)))
34  {
35  seq++;
36  switch(sq_gettype(v,-1))
37  {
38  case OT_NULL:
39  pf(v,_SC("[%s] NULL\n"),name);
40  break;
41  case OT_INTEGER:
42  sq_getinteger(v,-1,&i);
43  pf(v,_SC("[%s] %d\n"),name,i);
44  break;
45  case OT_FLOAT:
46  sq_getfloat(v,-1,&f);
47  pf(v,_SC("[%s] %.14g\n"),name,f);
48  break;
49  case OT_USERPOINTER:
50  pf(v,_SC("[%s] USERPOINTER\n"),name);
51  break;
52  case OT_STRING:
53  sq_getstring(v,-1,&s);
54  pf(v,_SC("[%s] \"%s\"\n"),name,s);
55  break;
56  case OT_TABLE:
57  pf(v,_SC("[%s] TABLE\n"),name);
58  break;
59  case OT_ARRAY:
60  pf(v,_SC("[%s] ARRAY\n"),name);
61  break;
62  case OT_CLOSURE:
63  pf(v,_SC("[%s] CLOSURE\n"),name);
64  break;
65  case OT_NATIVECLOSURE:
66  pf(v,_SC("[%s] NATIVECLOSURE\n"),name);
67  break;
68  case OT_GENERATOR:
69  pf(v,_SC("[%s] GENERATOR\n"),name);
70  break;
71  case OT_USERDATA:
72  pf(v,_SC("[%s] USERDATA\n"),name);
73  break;
74  case OT_THREAD:
75  pf(v,_SC("[%s] THREAD\n"),name);
76  break;
77  case OT_CLASS:
78  pf(v,_SC("[%s] CLASS\n"),name);
79  break;
80  case OT_INSTANCE:
81  pf(v,_SC("[%s] INSTANCE\n"),name);
82  break;
83  case OT_WEAKREF:
84  pf(v,_SC("[%s] WEAKREF\n"),name);
85  break;
86  case OT_BOOL:{
87  sq_getbool(v,-1,&b);
88  pf(v,_SC("[%s] %s\n"),name,b?_SC("true"):_SC("false"));
89  }
90  break;
91  default: assert(0); break;
92  }
93  sq_pop(v,1);
94  }
95  }
96  }
97 }
98 
99 static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
100 {
101  SQPRINTFUNCTION pf = sq_getprintfunc(v);
102  if(pf) {
103  const SQChar *sErr = 0;
104  if(sq_gettop(v)>=1) {
105  if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) {
106  pf(v,_SC("\nAN ERROR HAS OCCURED [%s]\n"),sErr);
107  }
108  else{
109  pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n"));
110  }
112  }
113  }
114  return 0;
115 }
116 
117 void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column)
118 {
119  SQPRINTFUNCTION pf = sq_getprintfunc(v);
120  if(pf) {
121  pf(v,_SC("%s line = (%d) column = (%d) : error %s\n"),sSource,line,column,sErr);
122  }
123 }
124 
125 void sqstd_seterrorhandlers(HSQUIRRELVM v)
126 {
130 }
void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
Definition: sqapi.cpp:678
void sqstd_printcallstack(HSQUIRRELVM v)
Definition: sqstdaux.cpp:6
void sqstd_seterrorhandlers(HSQUIRRELVM v)
Definition: sqstdaux.cpp:125
SQRESULT sq_getinteger(HSQUIRRELVM v, SQInteger idx, SQInteger *i)
Definition: sqapi.cpp:509
SQInteger sq_gettop(HSQUIRRELVM v)
Definition: sqapi.cpp:664
void sq_newclosure(HSQUIRRELVM v, SQFUNCTION func, SQUnsignedInteger nfreevars)
Definition: sqapi.cpp:338
void sq_setcompilererrorhandler(HSQUIRRELVM v, SQCOMPILERERROR f)
Definition: sqapi.cpp:1012
SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v)
Definition: sqapi.cpp:1254
SQRESULT sq_getfloat(HSQUIRRELVM v, SQInteger idx, SQFloat *f)
Definition: sqapi.cpp:519
void _sqstd_compiler_error(HSQUIRRELVM v, const SQChar *sErr, const SQChar *sSource, SQInteger line, SQInteger column)
Definition: sqstdaux.cpp:117
static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
Definition: sqstdaux.cpp:99
SQObjectType sq_gettype(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:489
SQRESULT sq_getstring(HSQUIRRELVM v, SQInteger idx, const SQChar **c)
Definition: sqapi.cpp:539
void sq_seterrorhandler(HSQUIRRELVM v)
Definition: sqapi.cpp:92
const SQChar * sq_getlocal(HSQUIRRELVM v, SQUnsignedInteger level, SQUnsignedInteger idx)
Definition: sqapi.cpp:883
char SQChar
SQRESULT sq_getbool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
Definition: sqapi.cpp:529
SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
Definition: sqdebug.cpp:28