5 #include "wrapper_util.hpp"
7 std::string squirrel2string(HSQUIRRELVM v, int i)
10 switch(sq_gettype(v, i))
26 sq_getinteger(v, i, &val);
32 sq_getfloat(v, i, &val);
38 sq_getstring(v, i, &val);
39 os << "\"" << val << "\"";
45 sq_pushnull(v); //null iterator
46 while(SQ_SUCCEEDED(sq_next(v,i-1)))
53 //here -1 is the value and -2 is the key
54 os << squirrel2string(v, -2) << " => "
55 << squirrel2string(v, -1);
57 sq_pop(v,2); //pops key and val before the nex iteration
66 sq_pushnull(v); //null iterator
67 while(SQ_SUCCEEDED(sq_next(v,i-1)))
74 //here -1 is the value and -2 is the key
75 // we ignore the key, since that is just the index in an array
76 os << squirrel2string(v, -1);
78 sq_pop(v,2); //pops key and val before the nex iteration
88 os << "<closure (function)>";
90 case OT_NATIVECLOSURE:
91 os << "<native closure (C function)>";
115 void print_squirrel_stack(HSQUIRRELVM v)
117 printf("--------------------------------------------------------------\n");
118 int count = sq_gettop(v);
119 for(int i = 1; i <= count; ++i) {
121 switch(sq_gettype(v, i))
128 sq_getinteger(v, i, &val);
129 printf("integer (%d)", val);
134 sq_getfloat(v, i, &val);
135 printf("float (%f)", val);
140 sq_getstring(v, i, &val);
141 printf("string (%s)", val);
154 printf("closure(function)");
156 case OT_NATIVECLOSURE:
157 printf("native closure(C function)");
163 printf("userpointer");
175 printf("unknown?!?");
180 printf("--------------------------------------------------------------\n");