Code::Blocks  SVN r11506
sqapi.cpp
Go to the documentation of this file.
1 /*
2  see copyright notice in squirrel.h
3 */
4 #include "sqpcheader.h"
5 #include "sqvm.h"
6 #include "sqstring.h"
7 #include "sqtable.h"
8 #include "sqarray.h"
9 #include "sqfuncproto.h"
10 #include "sqclosure.h"
11 #include "squserdata.h"
12 #include "sqcompiler.h"
13 #include "sqfuncstate.h"
14 #include "sqclass.h"
15 
16 bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
17 {
18  *o = &stack_get(v,idx);
19  if(type(**o) != type){
20  SQObjectPtr oval = v->PrintObjVal(**o);
21  v->Raise_Error(_SC("wrong argument type, expected '%s' got '%.50s'"),IdType2Name(type),_stringval(oval));
22  return false;
23  }
24  return true;
25 }
26 
27 #define _GETSAFE_OBJ(v,idx,type,o) { if(!sq_aux_gettypedarg(v,idx,type,&o)) return SQ_ERROR; }
28 
29 #define sq_aux_paramscheck(v,count) \
30 { \
31  if(sq_gettop(v) < count){ v->Raise_Error(_SC("not enough params in the stack")); return SQ_ERROR; }\
32 }
33 
34 SQInteger sq_aux_throwobject(HSQUIRRELVM v,SQObjectPtr &e)
35 {
36  v->_lasterror = e;
37  return SQ_ERROR;
38 }
39 
40 SQInteger sq_aux_invalidtype(HSQUIRRELVM v,SQObjectType type)
41 {
42  scsprintf(_ss(v)->GetScratchPad(100), _SC("unexpected type %s"), IdType2Name(type));
43  return sq_throwerror(v, _ss(v)->GetScratchPad(-1));
44 }
45 
46 HSQUIRRELVM sq_open(SQInteger initialstacksize)
47 {
48  SQSharedState *ss;
49  SQVM *v;
50  sq_new(ss, SQSharedState);
51  ss->Init();
52  v = (SQVM *)SQ_MALLOC(sizeof(SQVM));
53  new (v) SQVM(ss);
54  ss->_root_vm = v;
55  if(v->Init(NULL, initialstacksize)) {
56  return v;
57  } else {
58  sq_delete(v, SQVM);
59  return NULL;
60  }
61  return v;
62 }
63 
64 HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize)
65 {
66  SQSharedState *ss;
67  SQVM *v;
68  ss=_ss(friendvm);
69 
70  v= (SQVM *)SQ_MALLOC(sizeof(SQVM));
71  new (v) SQVM(ss);
72 
73  if(v->Init(friendvm, initialstacksize)) {
74  friendvm->Push(v);
75  return v;
76  } else {
77  sq_delete(v, SQVM);
78  return NULL;
79  }
80 }
81 
82 SQInteger sq_getvmstate(HSQUIRRELVM v)
83 {
84  if(v->_suspended)
85  return SQ_VMSTATE_SUSPENDED;
86  else {
87  if(v->_callsstacksize != 0) return SQ_VMSTATE_RUNNING;
88  else return SQ_VMSTATE_IDLE;
89  }
90 }
91 
92 void sq_seterrorhandler(HSQUIRRELVM v)
93 {
94  SQObject o = stack_get(v, -1);
95  if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
96  v->_errorhandler = o;
97  v->Pop();
98  }
99 }
100 
101 void sq_setdebughook(HSQUIRRELVM v)
102 {
103  SQObject o = stack_get(v,-1);
104  if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
105  v->_debughook = o;
106  v->Pop();
107  }
108 }
109 
110 void sq_close(HSQUIRRELVM v)
111 {
112  SQSharedState *ss = _ss(v);
113  _thread(ss->_root_vm)->Finalize();
114  sq_delete(ss, SQSharedState);
115 }
116 
117 SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror)
118 {
119  SQObjectPtr o;
120  if(Compile(v, read, p, sourcename, o, raiseerror?true:false, _ss(v)->_debuginfo)) {
121  v->Push(SQClosure::Create(_ss(v), _funcproto(o)));
122  return SQ_OK;
123  }
124  return SQ_ERROR;
125 }
126 
127 void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable)
128 {
129  _ss(v)->_debuginfo = enable?true:false;
130 }
131 
132 void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable)
133 {
134  _ss(v)->_notifyallexceptions = enable?true:false;
135 }
136 
137 void sq_addref(HSQUIRRELVM v,HSQOBJECT *po)
138 {
139  if(!ISREFCOUNTED(type(*po))) return;
140 #ifdef NO_GARBAGE_COLLECTOR
141  __AddRef(po->_type,po->_unVal);
142 #else
143  _ss(v)->_refs_table.AddRef(*po);
144 #endif
145 }
146 
147 SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po)
148 {
149  if(!ISREFCOUNTED(type(*po))) return SQTrue;
150 #ifdef NO_GARBAGE_COLLECTOR
151  __Release(po->_type,po->_unVal);
152  return SQFalse; //the ret val doesn't work(and cannot be fixed)
153 #else
154  return _ss(v)->_refs_table.Release(*po);
155 #endif
156 }
157 
158 const SQChar *sq_objtostring(HSQOBJECT *o)
159 {
160  if(sq_type(*o) == OT_STRING) {
161  return _stringval(*o);
162  }
163  return NULL;
164 }
165 
166 SQInteger sq_objtointeger(HSQOBJECT *o)
167 {
168  if(sq_isnumeric(*o)) {
169  return tointeger(*o);
170  }
171  return 0;
172 }
173 
174 SQFloat sq_objtofloat(HSQOBJECT *o)
175 {
176  if(sq_isnumeric(*o)) {
177  return tofloat(*o);
178  }
179  return 0;
180 }
181 
182 SQBool sq_objtobool(HSQOBJECT *o)
183 {
184  if(sq_isbool(*o)) {
185  return _integer(*o);
186  }
187  return SQFalse;
188 }
189 
190 void sq_pushnull(HSQUIRRELVM v)
191 {
192  v->Push(_null_);
193 }
194 
195 void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len)
196 {
197  if(s)
198  v->Push(SQObjectPtr(SQString::Create(_ss(v), s, len)));
199  else v->Push(_null_);
200 }
201 
202 void sq_pushinteger(HSQUIRRELVM v,SQInteger n)
203 {
204  v->Push(n);
205 }
206 
207 void sq_pushbool(HSQUIRRELVM v,SQBool b)
208 {
209  v->Push(b?true:false);
210 }
211 
212 void sq_pushfloat(HSQUIRRELVM v,SQFloat n)
213 {
214  v->Push(n);
215 }
216 
217 void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p)
218 {
219  v->Push(p);
220 }
221 
222 SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size)
223 {
224  SQUserData *ud = SQUserData::Create(_ss(v), size);
225  v->Push(ud);
226  return ud->_val;
227 }
228 
229 void sq_newtable(HSQUIRRELVM v)
230 {
231  v->Push(SQTable::Create(_ss(v), 0));
232 }
233 
234 void sq_newarray(HSQUIRRELVM v,SQInteger size)
235 {
236  v->Push(SQArray::Create(_ss(v), size));
237 }
238 
239 SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase)
240 {
241  SQClass *baseclass = NULL;
242  if(hasbase) {
243  SQObjectPtr &base = stack_get(v,-1);
244  if(type(base) != OT_CLASS)
245  return sq_throwerror(v,_SC("invalid base type"));
246  baseclass = _class(base);
247  }
248  SQClass *newclass = SQClass::Create(_ss(v), baseclass);
249  if(baseclass) v->Pop();
250  v->Push(newclass);
251  return SQ_OK;
252 }
253 
254 SQBool sq_instanceof(HSQUIRRELVM v)
255 {
256  SQObjectPtr &inst = stack_get(v,-1);
257  SQObjectPtr &cl = stack_get(v,-2);
258  if(type(inst) != OT_INSTANCE || type(cl) != OT_CLASS)
259  return sq_throwerror(v,_SC("invalid param type"));
260  return _instance(inst)->InstanceOf(_class(cl))?SQTrue:SQFalse;
261 }
262 
263 SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx)
264 {
265  sq_aux_paramscheck(v,2);
266  SQObjectPtr *arr;
267  _GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
268  _array(*arr)->Append(v->GetUp(-1));
269  v->Pop(1);
270  return SQ_OK;
271 }
272 
273 SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
274 {
275  sq_aux_paramscheck(v, 1);
276  SQObjectPtr *arr;
277  _GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
278  if(_array(*arr)->Size() > 0) {
279  if(pushval != 0){ v->Push(_array(*arr)->Top()); }
280  _array(*arr)->Pop();
281  return SQ_OK;
282  }
283  return sq_throwerror(v, _SC("empty array"));
284 }
285 
286 SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize)
287 {
288  sq_aux_paramscheck(v,1);
289  SQObjectPtr *arr;
290  _GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
291  if(newsize >= 0) {
292  _array(*arr)->Resize(newsize);
293  return SQ_OK;
294  }
295  return sq_throwerror(v,_SC("negative size"));
296 }
297 
298 
299 SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx)
300 {
301  sq_aux_paramscheck(v, 1);
302  SQObjectPtr *o;
303  _GETSAFE_OBJ(v, idx, OT_ARRAY,o);
304  SQArray *arr = _array(*o);
305  if(arr->Size() > 0) {
306  SQObjectPtr t;
307  SQInteger size = arr->Size();
308  SQInteger n = size >> 1; size -= 1;
309  for(SQInteger i = 0; i < n; i++) {
310  t = arr->_values[i];
311  arr->_values[i] = arr->_values[size-i];
312  arr->_values[size-i] = t;
313  }
314  return SQ_OK;
315  }
316  return SQ_OK;
317 }
318 
319 SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx)
320 {
321  sq_aux_paramscheck(v, 1);
322  SQObjectPtr *arr;
323  _GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
324  return _array(*arr)->Remove(itemidx) ? SQ_OK : sq_throwerror(v,_SC("index out of range"));
325 }
326 
327 SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos)
328 {
329  sq_aux_paramscheck(v, 1);
330  SQObjectPtr *arr;
331  _GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
332  SQRESULT ret = _array(*arr)->Insert(destpos, v->GetUp(-1)) ? SQ_OK : sq_throwerror(v,_SC("index out of range"));
333  v->Pop();
334  return ret;
335 }
336 
337 
338 void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars)
339 {
340  SQNativeClosure *nc = SQNativeClosure::Create(_ss(v), func);
341  nc->_nparamscheck = 0;
342  for(SQUnsignedInteger i = 0; i < nfreevars; i++) {
343  nc->_outervalues.push_back(v->Top());
344  v->Pop();
345  }
346  v->Push(SQObjectPtr(nc));
347 }
348 
349 SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars)
350 {
351  SQObject o = stack_get(v, idx);
352  if(sq_isclosure(o)) {
353  SQClosure *c = _closure(o);
354  SQFunctionProto *proto = _funcproto(c->_function);
355  *nparams = (SQUnsignedInteger)proto->_nparameters;
356  *nfreevars = (SQUnsignedInteger)c->_outervalues.size();
357  return SQ_OK;
358  }
359  return sq_throwerror(v,_SC("the object is not a closure"));
360 }
361 
362 SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name)
363 {
364  SQObject o = stack_get(v, idx);
365  if(sq_isnativeclosure(o)) {
366  SQNativeClosure *nc = _nativeclosure(o);
367  nc->_name = SQString::Create(_ss(v),name);
368  return SQ_OK;
369  }
370  return sq_throwerror(v,_SC("the object is not a nativeclosure"));
371 }
372 
373 SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask)
374 {
375  SQObject o = stack_get(v, -1);
376  if(!sq_isnativeclosure(o))
377  return sq_throwerror(v, _SC("native closure expected"));
378  SQNativeClosure *nc = _nativeclosure(o);
379  nc->_nparamscheck = nparamscheck;
380  if(typemask) {
381  SQIntVec res;
382  if(!CompileTypemask(res, typemask))
383  return sq_throwerror(v, _SC("invalid typemask"));
384  nc->_typecheck.copy(res);
385  }
386  else {
387  nc->_typecheck.resize(0);
388  }
389  if(nparamscheck == SQ_MATCHTYPEMASKSTRING) {
390  nc->_nparamscheck = nc->_typecheck.size();
391  }
392  return SQ_OK;
393 }
394 
395 SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx)
396 {
397  SQObjectPtr &o = stack_get(v,idx);
398  if(!sq_isnativeclosure(o) &&
399  !sq_isclosure(o))
400  return sq_throwerror(v,_SC("the target is not a closure"));
401  SQObjectPtr &env = stack_get(v,-1);
402  if(!sq_istable(env) &&
403  !sq_isclass(env) &&
404  !sq_isinstance(env))
405  return sq_throwerror(v,_SC("invalid environment"));
406  SQObjectPtr w = _refcounted(env)->GetWeakRef(type(env));
407  SQObjectPtr ret;
408  if(sq_isclosure(o)) {
409  SQClosure *c = _closure(o)->Clone();
410  c->_env = w;
411  ret = c;
412  }
413  else { //then must be a native closure
414  SQNativeClosure *c = _nativeclosure(o)->Clone();
415  c->_env = w;
416  ret = c;
417  }
418  v->Pop();
419  v->Push(ret);
420  return SQ_OK;
421 }
422 
423 SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx)
424 {
425  SQObject &o=stack_get(v,idx);
426  switch(type(o)) {
427  case OT_TABLE: _table(o)->Clear(); break;
428  case OT_ARRAY: _array(o)->Resize(0); break;
429  default:
430  return sq_throwerror(v, _SC("clear only works on table and array"));
431  break;
432 
433  }
434  return SQ_OK;
435 }
436 
437 void sq_pushroottable(HSQUIRRELVM v)
438 {
439  v->Push(v->_roottable);
440 }
441 
442 void sq_pushregistrytable(HSQUIRRELVM v)
443 {
444  v->Push(_ss(v)->_registry);
445 }
446 
447 void sq_pushconsttable(HSQUIRRELVM v)
448 {
449  v->Push(_ss(v)->_consts);
450 }
451 
452 SQRESULT sq_setroottable(HSQUIRRELVM v)
453 {
454  SQObject o = stack_get(v, -1);
455  if(sq_istable(o) || sq_isnull(o)) {
456  v->_roottable = o;
457  v->Pop();
458  return SQ_OK;
459  }
460  return sq_throwerror(v, _SC("ivalid type"));
461 }
462 
463 SQRESULT sq_setconsttable(HSQUIRRELVM v)
464 {
465  SQObject o = stack_get(v, -1);
466  if(sq_istable(o)) {
467  _ss(v)->_consts = o;
468  v->Pop();
469  return SQ_OK;
470  }
471  return sq_throwerror(v, _SC("ivalid type, expected table"));
472 }
473 
474 void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p)
475 {
476  v->_foreignptr = p;
477 }
478 
479 SQUserPointer sq_getforeignptr(HSQUIRRELVM v)
480 {
481  return v->_foreignptr;
482 }
483 
484 void sq_push(HSQUIRRELVM v,SQInteger idx)
485 {
486  v->Push(stack_get(v, idx));
487 }
488 
489 SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx)
490 {
491  return type(stack_get(v, idx));
492 }
493 
494 
495 void sq_tostring(HSQUIRRELVM v,SQInteger idx)
496 {
497  SQObjectPtr &o = stack_get(v, idx);
498  SQObjectPtr res;
499  v->ToString(o,res);
500  v->Push(res);
501 }
502 
503 void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
504 {
505  SQObjectPtr &o = stack_get(v, idx);
506  *b = v->IsFalse(o)?SQFalse:SQTrue;
507 }
508 
509 SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i)
510 {
511  SQObjectPtr &o = stack_get(v, idx);
512  if(sq_isnumeric(o)) {
513  *i = tointeger(o);
514  return SQ_OK;
515  }
516  return SQ_ERROR;
517 }
518 
519 SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f)
520 {
521  SQObjectPtr &o = stack_get(v, idx);
522  if(sq_isnumeric(o)) {
523  *f = tofloat(o);
524  return SQ_OK;
525  }
526  return SQ_ERROR;
527 }
528 
529 SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b)
530 {
531  SQObjectPtr &o = stack_get(v, idx);
532  if(sq_isbool(o)) {
533  *b = _integer(o);
534  return SQ_OK;
535  }
536  return SQ_ERROR;
537 }
538 
539 SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c)
540 {
541  SQObjectPtr *o = NULL;
542  _GETSAFE_OBJ(v, idx, OT_STRING,o);
543  *c = _stringval(*o);
544  return SQ_OK;
545 }
546 
547 SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread)
548 {
549  SQObjectPtr *o = NULL;
550  _GETSAFE_OBJ(v, idx, OT_THREAD,o);
551  *thread = _thread(*o);
552  return SQ_OK;
553 }
554 
555 SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx)
556 {
557  SQObjectPtr &o = stack_get(v,idx);
558  v->Push(_null_);
559  if(!v->Clone(o, stack_get(v, -1))){
560  v->Pop();
561  return sq_aux_invalidtype(v, type(o));
562  }
563  return SQ_OK;
564 }
565 
566 SQInteger sq_getsize(HSQUIRRELVM v, SQInteger idx)
567 {
568  SQObjectPtr &o = stack_get(v, idx);
569  SQObjectType type = type(o);
570  switch(type) {
571  case OT_STRING: return _string(o)->_len;
572  case OT_TABLE: return _table(o)->CountUsed();
573  case OT_ARRAY: return _array(o)->Size();
574  case OT_USERDATA: return _userdata(o)->_size;
575  case OT_INSTANCE: return _instance(o)->_class->_udsize;
576  case OT_CLASS: return _class(o)->_udsize;
577  default:
578  return sq_aux_invalidtype(v, type);
579  }
580 }
581 
582 SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag)
583 {
584  SQObjectPtr *o = NULL;
585  _GETSAFE_OBJ(v, idx, OT_USERDATA,o);
586  (*p) = _userdataval(*o);
587  if(typetag) *typetag = _userdata(*o)->_typetag;
588  return SQ_OK;
589 }
590 
591 SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag)
592 {
593  SQObjectPtr &o = stack_get(v,idx);
594  switch(type(o)) {
595  case OT_USERDATA: _userdata(o)->_typetag = typetag; break;
596  case OT_CLASS: _class(o)->_typetag = typetag; break;
597  default: return sq_throwerror(v,_SC("invalid object type"));
598  }
599  return SQ_OK;
600 }
601 
602 SQRESULT sq_getobjtypetag(HSQOBJECT *o,SQUserPointer * typetag)
603 {
604  switch(type(*o)) {
605  case OT_INSTANCE: *typetag = _instance(*o)->_class->_typetag; break;
606  case OT_USERDATA: *typetag = _userdata(*o)->_typetag; break;
607  case OT_CLASS: *typetag = _class(*o)->_typetag; break;
608  default: return SQ_ERROR;
609  }
610  return SQ_OK;
611 }
612 
613 SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag)
614 {
615  SQObjectPtr &o = stack_get(v,idx);
616  if(SQ_FAILED(sq_getobjtypetag(&o,typetag)))
617  return sq_throwerror(v,_SC("invalid object type"));
618  return SQ_OK;
619 }
620 
621 SQRESULT sq_getuserpointer(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p)
622 {
623  SQObjectPtr *o = NULL;
624  _GETSAFE_OBJ(v, idx, OT_USERPOINTER,o);
625  (*p) = _userpointer(*o);
626  return SQ_OK;
627 }
628 
629 SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
630 {
631  SQObjectPtr &o = stack_get(v,idx);
632  if(type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
633  _instance(o)->_userpointer = p;
634  return SQ_OK;
635 }
636 
637 SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize)
638 {
639  SQObjectPtr &o = stack_get(v,idx);
640  if(type(o) != OT_CLASS) return sq_throwerror(v,_SC("the object is not a class"));
641  if(_class(o)->_locked) return sq_throwerror(v,_SC("the class is locked"));
642  _class(o)->_udsize = udsize;
643  return SQ_OK;
644 }
645 
646 
647 SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag)
648 {
649  SQObjectPtr &o = stack_get(v,idx);
650  if(type(o) != OT_INSTANCE) return sq_throwerror(v,_SC("the object is not a class instance"));
651  (*p) = _instance(o)->_userpointer;
652  if(typetag != 0) {
653  SQClass *cl = _instance(o)->_class;
654  do{
655  if(cl->_typetag == typetag)
656  return SQ_OK;
657  cl = cl->_base;
658  }while(cl != NULL);
659  return sq_throwerror(v,_SC("invalid type tag"));
660  }
661  return SQ_OK;
662 }
663 
664 SQInteger sq_gettop(HSQUIRRELVM v)
665 {
666  return (v->_top) - v->_stackbase;
667 }
668 
669 void sq_settop(HSQUIRRELVM v, SQInteger newtop)
670 {
671  SQInteger top = sq_gettop(v);
672  if(top > newtop)
673  sq_pop(v, top - newtop);
674  else
675  while(top++ < newtop) sq_pushnull(v);
676 }
677 
678 void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
679 {
680  assert(v->_top >= nelemstopop);
681  v->Pop(nelemstopop);
682 }
683 
684 void sq_poptop(HSQUIRRELVM v)
685 {
686  assert(v->_top >= 1);
687  v->Pop();
688 }
689 
690 
691 void sq_remove(HSQUIRRELVM v, SQInteger idx)
692 {
693  v->Remove(idx);
694 }
695 
696 SQInteger sq_cmp(HSQUIRRELVM v)
697 {
698  SQInteger res;
699  v->ObjCmp(stack_get(v, -1), stack_get(v, -2),res);
700  return res;
701 }
702 
703 SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
704 {
705  sq_aux_paramscheck(v, 3);
706  SQObjectPtr &self = stack_get(v, idx);
707  if(type(self) == OT_TABLE || type(self) == OT_CLASS) {
708  SQObjectPtr &key = v->GetUp(-2);
709  if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
710  v->NewSlot(self, key, v->GetUp(-1),bstatic?true:false);
711  v->Pop(2);
712  }
713  return SQ_OK;
714 }
715 
716 SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
717 {
718  sq_aux_paramscheck(v, 2);
719  SQObjectPtr *self;
720  _GETSAFE_OBJ(v, idx, OT_TABLE,self);
721  SQObjectPtr &key = v->GetUp(-1);
722  if(type(key) == OT_NULL) return sq_throwerror(v, _SC("null is not a valid key"));
723  SQObjectPtr res;
724  if(!v->DeleteSlot(*self, key, res)){
725  return SQ_ERROR;
726  }
727  if(pushval) v->GetUp(-1) = res;
728  else v->Pop(1);
729  return SQ_OK;
730 }
731 
732 SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx)
733 {
734  SQObjectPtr &self = stack_get(v, idx);
735  if(v->Set(self, v->GetUp(-2), v->GetUp(-1),false)) {
736  v->Pop(2);
737  return SQ_OK;
738  }
739  v->Raise_IdxError(v->GetUp(-2));return SQ_ERROR;
740 }
741 
742 SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx)
743 {
744  SQObjectPtr &self = stack_get(v, idx);
745  if(type(v->GetUp(-2)) == OT_NULL) return sq_throwerror(v, _SC("null key"));
746  switch(type(self)) {
747  case OT_TABLE:
748  _table(self)->NewSlot(v->GetUp(-2), v->GetUp(-1));
749  v->Pop(2);
750  return SQ_OK;
751  break;
752  case OT_CLASS:
753  _class(self)->NewSlot(_ss(v), v->GetUp(-2), v->GetUp(-1),false);
754  v->Pop(2);
755  return SQ_OK;
756  break;
757  case OT_INSTANCE:
758  if(_instance(self)->Set(v->GetUp(-2), v->GetUp(-1))) {
759  v->Pop(2);
760  return SQ_OK;
761  }
762  break;
763  case OT_ARRAY:
764  if(v->Set(self, v->GetUp(-2), v->GetUp(-1),false)) {
765  v->Pop(2);
766  return SQ_OK;
767  }
768  break;
769  default:
770  v->Pop(2);
771  return sq_throwerror(v, _SC("rawset works only on array/table/class and instance"));
772  }
773  v->Raise_IdxError(v->GetUp(-2));return SQ_ERROR;
774 }
775 
776 SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx)
777 {
778  SQObjectPtr &self = stack_get(v, idx);
779  SQObjectPtr &mt = v->GetUp(-1);
780  SQObjectType type = type(self);
781  switch(type) {
782  case OT_TABLE:
783  if(type(mt) == OT_TABLE) {
784  if(!_table(self)->SetDelegate(_table(mt))) return sq_throwerror(v, _SC("delagate cycle")); v->Pop();}
785  else if(type(mt)==OT_NULL) {
786  _table(self)->SetDelegate(NULL); v->Pop(); }
787  else return sq_aux_invalidtype(v,type);
788  break;
789  case OT_USERDATA:
790  if(type(mt)==OT_TABLE) {
791  _userdata(self)->SetDelegate(_table(mt)); v->Pop(); }
792  else if(type(mt)==OT_NULL) {
793  _userdata(self)->SetDelegate(NULL); v->Pop(); }
794  else return sq_aux_invalidtype(v, type);
795  break;
796  default:
797  return sq_aux_invalidtype(v, type);
798  break;
799  }
800  return SQ_OK;
801 }
802 
803 SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval)
804 {
805  sq_aux_paramscheck(v, 2);
806  SQObjectPtr *self;
807  _GETSAFE_OBJ(v, idx, OT_TABLE,self);
808  SQObjectPtr &key = v->GetUp(-1);
809  SQObjectPtr t;
810  if(_table(*self)->Get(key,t)) {
811  _table(*self)->Remove(key);
812  }
813  // C::B patch: Put brackets around inner if(...)
814  if(pushval != 0) {
815  if(pushval) v->GetUp(-1) = t;
816  }
817  else
818  v->Pop(1);
819  return SQ_OK;
820 }
821 
822 SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx)
823 {
824  SQObjectPtr &self=stack_get(v,idx);
825  switch(type(self)){
826  case OT_TABLE:
827  case OT_USERDATA:
828  if(!_delegable(self)->_delegate){
829  v->Push(_null_);
830  break;
831  }
832  v->Push(SQObjectPtr(_delegable(self)->_delegate));
833  break;
834  default: return sq_throwerror(v,_SC("wrong type")); break;
835  }
836  return SQ_OK;
837 
838 }
839 
840 SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx)
841 {
842  SQObjectPtr &self=stack_get(v,idx);
843  if(v->Get(self,v->GetUp(-1),v->GetUp(-1),false,false))
844  return SQ_OK;
845  v->Pop(1);
846  return sq_throwerror(v,_SC("the index doesn't exist"));
847 }
848 
849 SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx)
850 {
851  SQObjectPtr &self=stack_get(v,idx);
852  switch(type(self)) {
853  case OT_TABLE:
854  if(_table(self)->Get(v->GetUp(-1),v->GetUp(-1)))
855  return SQ_OK;
856  break;
857  case OT_CLASS:
858  if(_class(self)->Get(v->GetUp(-1),v->GetUp(-1)))
859  return SQ_OK;
860  break;
861  case OT_INSTANCE:
862  if(_instance(self)->Get(v->GetUp(-1),v->GetUp(-1)))
863  return SQ_OK;
864  break;
865  case OT_ARRAY:
866  if(v->Get(self,v->GetUp(-1),v->GetUp(-1),false,false))
867  return SQ_OK;
868  break;
869  default:
870  v->Pop(1);
871  return sq_throwerror(v,_SC("rawget works only on array/table/instance and class"));
872  }
873  v->Pop(1);
874  return sq_throwerror(v,_SC("the index doesn't exist"));
875 }
876 
877 SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po)
878 {
879  *po=stack_get(v,idx);
880  return SQ_OK;
881 }
882 
883 const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx)
884 {
885  SQUnsignedInteger cstksize=v->_callsstacksize;
886  SQUnsignedInteger lvl=(cstksize-level)-1;
887  SQInteger stackbase=v->_stackbase;
888  if(lvl<cstksize){
889  for(SQUnsignedInteger i=0;i<level;i++){
890  SQVM::CallInfo &ci=v->_callsstack[(cstksize-i)-1];
891  stackbase-=ci._prevstkbase;
892  }
893  SQVM::CallInfo &ci=v->_callsstack[lvl];
894  if(type(ci._closure)!=OT_CLOSURE)
895  return NULL;
896  SQClosure *c=_closure(ci._closure);
897  SQFunctionProto *func=_funcproto(c->_function);
898  if(func->_noutervalues > (SQInteger)idx) {
899  v->Push(c->_outervalues[idx]);
900  return _stringval(func->_outervalues[idx]._name);
901  }
902  idx -= func->_noutervalues;
903  return func->GetLocal(v,stackbase,idx,(SQInteger)(ci._ip-func->_instructions)-1);
904  }
905  return NULL;
906 }
907 
908 void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj)
909 {
910  v->Push(SQObjectPtr(obj));
911 }
912 
913 void sq_resetobject(HSQOBJECT *po)
914 {
915  po->_unVal.pUserPointer=NULL;po->_type=OT_NULL;
916 }
917 
918 SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err)
919 {
920  v->_lasterror=SQString::Create(_ss(v),err);
921  return -1;
922 }
923 
924 void sq_reseterror(HSQUIRRELVM v)
925 {
926  v->_lasterror = _null_;
927 }
928 
929 void sq_getlasterror(HSQUIRRELVM v)
930 {
931  v->Push(v->_lasterror);
932 }
933 
934 void sq_reservestack(HSQUIRRELVM v,SQInteger nsize)
935 {
936  if (((SQUnsignedInteger)v->_top + nsize) > v->_stack.size()) {
937  v->_stack.resize(v->_stack.size() + ((v->_top + nsize) - v->_stack.size()));
938  }
939 }
940 
941 SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
942 {
943  if(type(v->GetUp(-1))==OT_GENERATOR){
944  v->Push(_null_); //retval
945  if(!v->Execute(v->GetUp(-2),v->_top,0,v->_top,v->GetUp(-1),raiseerror,SQVM::ET_RESUME_GENERATOR))
946  {v->Raise_Error(v->_lasterror); return SQ_ERROR;}
947  if(!retval)
948  v->Pop();
949  return SQ_OK;
950  }
951  return sq_throwerror(v,_SC("only generators can be resumed"));
952 }
953 
954 SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
955 {
956  SQObjectPtr res;
957  if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
958  if(!v->_suspended) {
959  v->Pop(params);//pop closure and args
960  }
961  if(retval){
962  v->Push(res); return SQ_OK;
963  }
964  return SQ_OK;
965  }
966  else {
967  v->Pop(params);
968  return SQ_ERROR;
969  }
970  if(!v->_suspended)
971  v->Pop(params);
972  return sq_throwerror(v,_SC("call failed"));
973 }
974 
975 SQRESULT sq_suspendvm(HSQUIRRELVM v)
976 {
977  return v->Suspend();
978 }
979 
980 SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool wakeupret,SQBool retval,SQBool raiseerror,SQBool throwerror)
981 {
982  SQObjectPtr ret;
983  if(!v->_suspended)
984  return sq_throwerror(v,_SC("cannot resume a vm that is not running any code"));
985  if(wakeupret) {
986  v->GetAt(v->_stackbase+v->_suspended_target)=v->GetUp(-1); //retval
987  v->Pop();
988  } else v->GetAt(v->_stackbase+v->_suspended_target)=_null_;
989  if(!v->Execute(_null_,v->_top,-1,-1,ret,raiseerror,throwerror?SQVM::ET_RESUME_THROW_VM : SQVM::ET_RESUME_VM))
990  return SQ_ERROR;
991  if(sq_getvmstate(v) == SQ_VMSTATE_IDLE) {
992  while (v->_top > 1) v->_stack[--v->_top] = _null_;
993  }
994  if(retval)
995  v->Push(ret);
996  return SQ_OK;
997 }
998 
999 void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook)
1000 {
1001  if(sq_gettop(v) >= 1){
1002  SQObjectPtr &ud=stack_get(v,idx);
1003  switch( type(ud) ) {
1004  case OT_USERDATA: _userdata(ud)->_hook = hook; break;
1005  case OT_INSTANCE: _instance(ud)->_hook = hook; break;
1006  case OT_CLASS: _class(ud)->_hook = hook; break;
1007  default: break; //shutup compiler
1008  }
1009  }
1010 }
1011 
1012 void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f)
1013 {
1014  _ss(v)->_compilererrorhandler = f;
1015 }
1016 
1017 SQRESULT sq_writeclosure(HSQUIRRELVM v,SQWRITEFUNC w,SQUserPointer up)
1018 {
1019  SQObjectPtr *o = NULL;
1020  _GETSAFE_OBJ(v, -1, OT_CLOSURE,o);
1021  unsigned short tag = SQ_BYTECODE_STREAM_TAG;
1022  if(w(up,&tag,2) != 2)
1023  return sq_throwerror(v,_SC("io error"));
1024  if(!_closure(*o)->Save(v,up,w))
1025  return SQ_ERROR;
1026  return SQ_OK;
1027 }
1028 
1029 SQRESULT sq_readclosure(HSQUIRRELVM v,SQREADFUNC r,SQUserPointer up)
1030 {
1031  SQObjectPtr closure;
1032 
1033  unsigned short tag;
1034  if(r(up,&tag,2) != 2)
1035  return sq_throwerror(v,_SC("io error"));
1036  if(tag != SQ_BYTECODE_STREAM_TAG)
1037  return sq_throwerror(v,_SC("invalid stream"));
1038  if(!SQClosure::Load(v,up,r,closure))
1039  return SQ_ERROR;
1040  v->Push(closure);
1041  return SQ_OK;
1042 }
1043 
1044 SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize)
1045 {
1046  return _ss(v)->GetScratchPad(minsize);
1047 }
1048 
1049 SQInteger sq_collectgarbage(HSQUIRRELVM v)
1050 {
1051 #ifndef NO_GARBAGE_COLLECTOR
1052  return _ss(v)->CollectGarbage(v);
1053 #else
1054  return -1;
1055 #endif
1056 }
1057 
1058 const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval)
1059 {
1060  SQObjectPtr &self = stack_get(v,idx);
1061  const SQChar *name = NULL;
1062  if(type(self) == OT_CLOSURE) {
1063  if(_closure(self)->_outervalues.size()>nval) {
1064  v->Push(_closure(self)->_outervalues[nval]);
1065  SQFunctionProto *fp = _funcproto(_closure(self)->_function);
1066  SQOuterVar &ov = fp->_outervalues[nval];
1067  name = _stringval(ov._name);
1068  }
1069  }
1070  return name;
1071 }
1072 
1073 SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval)
1074 {
1075  SQObjectPtr &self=stack_get(v,idx);
1076  switch(type(self))
1077  {
1078  case OT_CLOSURE:
1079  if(_closure(self)->_outervalues.size()>nval){
1080  _closure(self)->_outervalues[nval]=stack_get(v,-1);
1081  }
1082  else return sq_throwerror(v,_SC("invalid free var index"));
1083  break;
1084  case OT_NATIVECLOSURE:
1085  if(_nativeclosure(self)->_outervalues.size()>nval){
1086  _nativeclosure(self)->_outervalues[nval]=stack_get(v,-1);
1087  }
1088  else return sq_throwerror(v,_SC("invalid free var index"));
1089  break;
1090  default:
1091  return sq_aux_invalidtype(v,type(self));
1092  }
1093  v->Pop(1);
1094  return SQ_OK;
1095 }
1096 
1097 SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx)
1098 {
1099  SQObjectPtr *o = NULL;
1100  _GETSAFE_OBJ(v, idx, OT_CLASS,o);
1101  SQObjectPtr &key = stack_get(v,-2);
1102  SQObjectPtr &val = stack_get(v,-1);
1103  SQObjectPtr attrs;
1104  if(type(key) == OT_NULL) {
1105  attrs = _class(*o)->_attributes;
1106  _class(*o)->_attributes = val;
1107  v->Pop(2);
1108  v->Push(attrs);
1109  return SQ_OK;
1110  }else if(_class(*o)->GetAttributes(key,attrs)) {
1111  _class(*o)->SetAttributes(key,val);
1112  v->Pop(2);
1113  v->Push(attrs);
1114  return SQ_OK;
1115  }
1116  return sq_throwerror(v,_SC("wrong index"));
1117 }
1118 
1119 SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx)
1120 {
1121  SQObjectPtr *o = NULL;
1122  _GETSAFE_OBJ(v, idx, OT_CLASS,o);
1123  SQObjectPtr &key = stack_get(v,-1);
1124  SQObjectPtr attrs;
1125  if(type(key) == OT_NULL) {
1126  attrs = _class(*o)->_attributes;
1127  v->Pop();
1128  v->Push(attrs);
1129  return SQ_OK;
1130  }
1131  else if(_class(*o)->GetAttributes(key,attrs)) {
1132  v->Pop();
1133  v->Push(attrs);
1134  return SQ_OK;
1135  }
1136  return sq_throwerror(v,_SC("wrong index"));
1137 }
1138 
1139 SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx)
1140 {
1141  SQObjectPtr *o = NULL;
1142  _GETSAFE_OBJ(v, idx, OT_CLASS,o);
1143  if(_class(*o)->_base)
1144  v->Push(SQObjectPtr(_class(*o)->_base));
1145  else
1146  v->Push(_null_);
1147  return SQ_OK;
1148 }
1149 
1150 SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx)
1151 {
1152  SQObjectPtr *o = NULL;
1153  _GETSAFE_OBJ(v, idx, OT_INSTANCE,o);
1154  v->Push(SQObjectPtr(_instance(*o)->_class));
1155  return SQ_OK;
1156 }
1157 
1158 SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx)
1159 {
1160  SQObjectPtr *o = NULL;
1161  _GETSAFE_OBJ(v, idx, OT_CLASS,o);
1162  v->Push(_class(*o)->CreateInstance());
1163  return SQ_OK;
1164 }
1165 
1166 void sq_weakref(HSQUIRRELVM v,SQInteger idx)
1167 {
1168  SQObject &o=stack_get(v,idx);
1169  if(ISREFCOUNTED(type(o))) {
1170  v->Push(_refcounted(o)->GetWeakRef(type(o)));
1171  return;
1172  }
1173  v->Push(o);
1174 }
1175 
1176 SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx)
1177 {
1178  SQObjectPtr &o = stack_get(v,idx);
1179  if(type(o) != OT_WEAKREF) {
1180  return sq_throwerror(v,_SC("the object must be a weakref"));
1181  }
1182  v->Push(_weakref(o)->_obj);
1183  return SQ_OK;
1184 }
1185 
1186 SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t)
1187 {
1188  SQSharedState *ss = _ss(v);
1189  switch(t) {
1190  case OT_TABLE: v->Push(ss->_table_default_delegate); break;
1191  case OT_ARRAY: v->Push(ss->_array_default_delegate); break;
1192  case OT_STRING: v->Push(ss->_string_default_delegate); break;
1193  case OT_INTEGER: case OT_FLOAT: v->Push(ss->_number_default_delegate); break;
1194  case OT_GENERATOR: v->Push(ss->_generator_default_delegate); break;
1195  case OT_CLOSURE: case OT_NATIVECLOSURE: v->Push(ss->_closure_default_delegate); break;
1196  case OT_THREAD: v->Push(ss->_thread_default_delegate); break;
1197  case OT_CLASS: v->Push(ss->_class_default_delegate); break;
1198  case OT_INSTANCE: v->Push(ss->_instance_default_delegate); break;
1199  case OT_WEAKREF: v->Push(ss->_weakref_default_delegate); break;
1200  default: return sq_throwerror(v,_SC("the type doesn't have a default delegate"));
1201  }
1202  return SQ_OK;
1203 }
1204 
1205 SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx)
1206 {
1207  SQObjectPtr o=stack_get(v,idx),&refpos = stack_get(v,-1),realkey,val;
1208  if(type(o) == OT_GENERATOR) {
1209  return sq_throwerror(v,_SC("cannot iterate a generator"));
1210  }
1211  int faketojump;
1212  if(!v->FOREACH_OP(o,realkey,val,refpos,0,666,faketojump))
1213  return SQ_ERROR;
1214  if(faketojump != 666) {
1215  v->Push(realkey);
1216  v->Push(val);
1217  return SQ_OK;
1218  }
1219  return SQ_ERROR;
1220 }
1221 
1222 struct BufState{
1223  const SQChar *buf;
1224  SQInteger ptr;
1225  SQInteger size;
1226 };
1227 
1228 SQInteger buf_lexfeed(SQUserPointer file)
1229 {
1230  BufState *buf=(BufState*)file;
1231  if(buf->size<(buf->ptr+1))
1232  return 0;
1233  return buf->buf[buf->ptr++];
1234 }
1235 
1236 SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror) {
1237  BufState buf;
1238  buf.buf = s;
1239  buf.size = size;
1240  buf.ptr = 0;
1241  return sq_compile(v, buf_lexfeed, &buf, sourcename, raiseerror);
1242 }
1243 
1244 void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx)
1245 {
1246  dest->Push(stack_get(src,idx));
1247 }
1248 
1249 void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc)
1250 {
1251  _ss(v)->_printfunc = printfunc;
1252 }
1253 
1254 SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v)
1255 {
1256  return _ss(v)->_printfunc;
1257 }
1258 
1259 void *sq_malloc(SQUnsignedInteger size)
1260 {
1261  return SQ_MALLOC(size);
1262 }
1263 
1264 void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize)
1265 {
1266  return SQ_REALLOC(p,oldsize,newsize);
1267 }
1268 
1269 void sq_free(void *p,SQUnsignedInteger size)
1270 {
1271  SQ_FREE(p,size);
1272 }
SQRESULT sq_resume(HSQUIRRELVM v, SQBool retval, SQBool raiseerror)
Definition: sqapi.cpp:941
SQRESULT sq_get(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:840
void sq_setdebughook(HSQUIRRELVM v)
Definition: sqapi.cpp:101
SQRESULT sq_arraypop(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
Definition: sqapi.cpp:273
SQRESULT sq_setconsttable(HSQUIRRELVM v)
Definition: sqapi.cpp:463
SQRESULT sq_newclass(HSQUIRRELVM v, SQBool hasbase)
Definition: sqapi.cpp:239
SQRESULT sq_rawget(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:849
SQRESULT sq_arrayinsert(HSQUIRRELVM v, SQInteger idx, SQInteger destpos)
Definition: sqapi.cpp:327
SQRESULT sq_setattributes(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1097
SQRESULT sq_rawdeleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
Definition: sqapi.cpp:803
SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p, SQUserPointer typetag)
Definition: sqapi.cpp:647
SQRESULT sq_clone(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:555
void * sq_malloc(SQUnsignedInteger size)
Definition: sqapi.cpp:1259
SQObjectPtr _null_
Definition: sqstate.cpp:15
void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
Definition: sqapi.cpp:678
SQRESULT sq_getuserdata(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p, SQUserPointer *typetag)
Definition: sqapi.cpp:582
const SQChar * sq_getfreevariable(HSQUIRRELVM v, SQInteger idx, SQUnsignedInteger nval)
Definition: sqapi.cpp:1058
SQRESULT sq_setroottable(HSQUIRRELVM v)
Definition: sqapi.cpp:452
SQRESULT sq_gettypetag(HSQUIRRELVM v, SQInteger idx, SQUserPointer *typetag)
Definition: sqapi.cpp:613
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
Definition: sqapi.cpp:918
SQInteger sq_collectgarbage(HSQUIRRELVM v)
Definition: sqapi.cpp:1049
void sq_newtable(HSQUIRRELVM v)
Definition: sqapi.cpp:229
void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable)
Definition: sqapi.cpp:127
SQInteger size
Definition: sqapi.cpp:1225
SQInteger buf_lexfeed(SQUserPointer file)
Definition: sqapi.cpp:1228
SQRESULT sq_rawset(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:742
SQRESULT sq_wakeupvm(HSQUIRRELVM v, SQBool wakeupret, SQBool retval, SQBool raiseerror, SQBool throwerror)
Definition: sqapi.cpp:980
SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v, SQObjectType t)
Definition: sqapi.cpp:1186
void sq_reservestack(HSQUIRRELVM v, SQInteger nsize)
Definition: sqapi.cpp:934
void sq_pushnull(HSQUIRRELVM v)
Definition: sqapi.cpp:190
SQRESULT sq_getweakrefval(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1176
SQRESULT sq_bindenv(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:395
SQRESULT sq_getbase(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1139
void sq_pushroottable(HSQUIRRELVM v)
Definition: sqapi.cpp:437
void sq_pushregistrytable(HSQUIRRELVM v)
Definition: sqapi.cpp:442
bool CompileTypemask(SQIntVec &res, const SQChar *typemask)
Definition: sqstate.cpp:38
void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
Definition: sqapi.cpp:503
SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:263
void sq_pushfloat(HSQUIRRELVM v, SQFloat n)
Definition: sqapi.cpp:212
SQInteger sq_getvmstate(HSQUIRRELVM v)
Definition: sqapi.cpp:82
SQUserPointer sq_getforeignptr(HSQUIRRELVM v)
Definition: sqapi.cpp:479
HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize)
Definition: sqapi.cpp:64
SQRESULT sq_writeclosure(HSQUIRRELVM v, SQWRITEFUNC w, SQUserPointer up)
Definition: sqapi.cpp:1017
SQRESULT sq_getinteger(HSQUIRRELVM v, SQInteger idx, SQInteger *i)
Definition: sqapi.cpp:509
SQInteger sq_getsize(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:566
SQInteger sq_gettop(HSQUIRRELVM v)
Definition: sqapi.cpp:664
void sq_pushconsttable(HSQUIRRELVM v)
Definition: sqapi.cpp:447
void sq_pushinteger(HSQUIRRELVM v, SQInteger n)
Definition: sqapi.cpp:202
void sq_newclosure(HSQUIRRELVM v, SQFUNCTION func, SQUnsignedInteger nfreevars)
Definition: sqapi.cpp:338
SQRESULT sq_next(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1205
SQRESULT sq_call(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool raiseerror)
Definition: sqapi.cpp:954
void sq_push(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:484
#define _GETSAFE_OBJ(v, idx, type, o)
Definition: sqapi.cpp:27
SQRESULT sq_arrayremove(HSQUIRRELVM v, SQInteger idx, SQInteger itemidx)
Definition: sqapi.cpp:319
void sq_poptop(HSQUIRRELVM v)
Definition: sqapi.cpp:684
SQRESULT sq_getclosureinfo(HSQUIRRELVM v, SQInteger idx, SQUnsignedInteger *nparams, SQUnsignedInteger *nfreevars)
Definition: sqapi.cpp:349
SQBool sq_release(HSQUIRRELVM v, HSQOBJECT *po)
Definition: sqapi.cpp:147
void sq_setcompilererrorhandler(HSQUIRRELVM v, SQCOMPILERERROR f)
Definition: sqapi.cpp:1012
SQRESULT sq_clear(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:423
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v, SQInteger idx, const SQChar *name)
Definition: sqapi.cpp:362
void sq_settop(HSQUIRRELVM v, SQInteger newtop)
Definition: sqapi.cpp:669
SQInteger ptr
Definition: sqapi.cpp:1224
SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v)
Definition: sqapi.cpp:1254
SQRESULT sq_compile(HSQUIRRELVM v, SQLEXREADFUNC read, SQUserPointer p, const SQChar *sourcename, SQBool raiseerror)
Definition: sqapi.cpp:117
void sq_tostring(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:495
SQRESULT sq_getthread(HSQUIRRELVM v, SQInteger idx, HSQUIRRELVM *thread)
Definition: sqapi.cpp:547
void sq_reseterror(HSQUIRRELVM v)
Definition: sqapi.cpp:924
SQInteger sq_cmp(HSQUIRRELVM v)
Definition: sqapi.cpp:696
bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo)
SQRESULT sq_arrayresize(HSQUIRRELVM v, SQInteger idx, SQInteger newsize)
Definition: sqapi.cpp:286
SQRESULT sq_getfloat(HSQUIRRELVM v, SQInteger idx, SQFloat *f)
Definition: sqapi.cpp:519
SQRESULT sq_getattributes(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1119
void * sq_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger newsize)
Definition: sqapi.cpp:1264
SQRESULT sq_suspendvm(HSQUIRRELVM v)
Definition: sqapi.cpp:975
void sq_remove(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:691
SQRESULT sq_setparamscheck(HSQUIRRELVM v, SQInteger nparamscheck, const SQChar *typemask)
Definition: sqapi.cpp:373
void sq_setforeignptr(HSQUIRRELVM v, SQUserPointer p)
Definition: sqapi.cpp:474
SQRESULT sq_getobjtypetag(HSQOBJECT *o, SQUserPointer *typetag)
Definition: sqapi.cpp:602
void sq_pushstring(HSQUIRRELVM v, const SQChar *s, SQInteger len)
Definition: sqapi.cpp:195
SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
Definition: sqapi.cpp:629
const SQChar * IdType2Name(SQObjectType type)
Definition: sqobject.cpp:15
SQObjectType sq_gettype(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:489
SQRESULT sq_setfreevariable(HSQUIRRELVM v, SQInteger idx, SQUnsignedInteger nval)
Definition: sqapi.cpp:1073
SQBool sq_instanceof(HSQUIRRELVM v)
Definition: sqapi.cpp:254
SQRESULT sq_getclass(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1150
void sq_close(HSQUIRRELVM v)
Definition: sqapi.cpp:110
SQRESULT sq_getstring(HSQUIRRELVM v, SQInteger idx, const SQChar **c)
Definition: sqapi.cpp:539
SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize)
Definition: sqapi.cpp:637
void sq_seterrorhandler(HSQUIRRELVM v)
Definition: sqapi.cpp:92
void sq_getlasterror(HSQUIRRELVM v)
Definition: sqapi.cpp:929
const SQChar * sq_objtostring(HSQOBJECT *o)
Definition: sqapi.cpp:158
const SQChar * sq_getlocal(HSQUIRRELVM v, SQUnsignedInteger level, SQUnsignedInteger idx)
Definition: sqapi.cpp:883
SQRESULT sq_readclosure(HSQUIRRELVM v, SQREADFUNC r, SQUserPointer up)
Definition: sqapi.cpp:1029
SQRESULT sq_getuserpointer(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p)
Definition: sqapi.cpp:621
char SQChar
SQRESULT sq_getbool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
Definition: sqapi.cpp:529
void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc)
Definition: sqapi.cpp:1249
void sq_free(void *p, SQUnsignedInteger size)
Definition: sqapi.cpp:1269
void sq_resetobject(HSQOBJECT *po)
Definition: sqapi.cpp:913
SQInteger sq_aux_invalidtype(HSQUIRRELVM v, SQObjectType type)
Definition: sqapi.cpp:40
SQUserPointer sq_newuserdata(HSQUIRRELVM v, SQUnsignedInteger size)
Definition: sqapi.cpp:222
SQRESULT sq_settypetag(HSQUIRRELVM v, SQInteger idx, SQUserPointer typetag)
Definition: sqapi.cpp:591
HSQUIRRELVM sq_open(SQInteger initialstacksize)
Definition: sqapi.cpp:46
SQInteger sq_aux_throwobject(HSQUIRRELVM v, SQObjectPtr &e)
Definition: sqapi.cpp:34
void sq_pushbool(HSQUIRRELVM v, SQBool b)
Definition: sqapi.cpp:207
void sq_weakref(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1166
void sq_addref(HSQUIRRELVM v, HSQOBJECT *po)
Definition: sqapi.cpp:137
void sq_newarray(HSQUIRRELVM v, SQInteger size)
Definition: sqapi.cpp:234
SQInteger sq_objtointeger(HSQOBJECT *o)
Definition: sqapi.cpp:166
SQRESULT sq_arrayreverse(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:299
SQChar * sq_getscratchpad(HSQUIRRELVM v, SQInteger minsize)
Definition: sqapi.cpp:1044
SQRESULT sq_getdelegate(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:822
SQRESULT sq_set(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:732
bool sq_aux_gettypedarg(HSQUIRRELVM v, SQInteger idx, SQObjectType type, SQObjectPtr **o)
Definition: sqapi.cpp:16
SQRESULT sq_getstackobj(HSQUIRRELVM v, SQInteger idx, HSQOBJECT *po)
Definition: sqapi.cpp:877
SQBool sq_objtobool(HSQOBJECT *o)
Definition: sqapi.cpp:182
SQRESULT sq_setdelegate(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:776
SQRESULT sq_deleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
Definition: sqapi.cpp:716
void sq_setreleasehook(HSQUIRRELVM v, SQInteger idx, SQRELEASEHOOK hook)
Definition: sqapi.cpp:999
const SQChar * buf
Definition: sqapi.cpp:1223
#define sq_aux_paramscheck(v, count)
Definition: sqapi.cpp:29
#define NULL
Definition: prefix.cpp:59
SQRESULT sq_compilebuffer(HSQUIRRELVM v, const SQChar *s, SQInteger size, const SQChar *sourcename, SQBool raiseerror)
Definition: sqapi.cpp:1236
void sq_pushobject(HSQUIRRELVM v, HSQOBJECT obj)
Definition: sqapi.cpp:908
SQFloat sq_objtofloat(HSQOBJECT *o)
Definition: sqapi.cpp:174
void sq_pushuserpointer(HSQUIRRELVM v, SQUserPointer p)
Definition: sqapi.cpp:217
SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
Definition: sqapi.cpp:703
SQRESULT sq_createinstance(HSQUIRRELVM v, SQInteger idx)
Definition: sqapi.cpp:1158
void sq_move(HSQUIRRELVM dest, HSQUIRRELVM src, SQInteger idx)
Definition: sqapi.cpp:1244
void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable)
Definition: sqapi.cpp:132