1/*
2Copyright (c) 2003-2017 Alberto Demichelis
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22#ifndef _SQUIRREL_H_
23#define _SQUIRREL_H_
24
25#ifdef _SQ_CONFIG_INCLUDE
26#include _SQ_CONFIG_INCLUDE
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#ifndef SQUIRREL_API
34#define SQUIRREL_API extern
35#endif
36
37#if (defined(_WIN64) || defined(_LP64))
38#ifndef _SQ64
39#define _SQ64
40#endif
41#endif
42
43
44#define SQTrue (1)
45#define SQFalse (0)
46
47struct SQVM;
48struct SQTable;
49struct SQArray;
50struct SQString;
51struct SQClosure;
52struct SQGenerator;
53struct SQNativeClosure;
54struct SQUserData;
55struct SQFunctionProto;
56struct SQRefCounted;
57struct SQClass;
58struct SQInstance;
59struct SQDelegable;
60struct SQOuter;
61
62#ifdef _UNICODE
63#define SQUNICODE
64#endif
65
66#include "sqconfig.h"
67
68#define SQUIRREL_VERSION _SC("Squirrel 3.1 stable")
69#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2017 Alberto Demichelis")
70#define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
71#define SQUIRREL_VERSION_NUMBER 310
72
73#define SQ_VMSTATE_IDLE 0
74#define SQ_VMSTATE_RUNNING 1
75#define SQ_VMSTATE_SUSPENDED 2
76
77#define SQUIRREL_EOB 0
78#define SQ_BYTECODE_STREAM_TAG 0xFAFA
79
80#define SQOBJECT_REF_COUNTED 0x08000000
81#define SQOBJECT_NUMERIC 0x04000000
82#define SQOBJECT_DELEGABLE 0x02000000
83#define SQOBJECT_CANBEFALSE 0x01000000
84
85#define SQ_MATCHTYPEMASKSTRING (-99999)
86
87#define _RT_MASK 0x00FFFFFF
88#define _RAW_TYPE(type) (type&_RT_MASK)
89
90#define _RT_NULL 0x00000001
91#define _RT_INTEGER 0x00000002
92#define _RT_FLOAT 0x00000004
93#define _RT_BOOL 0x00000008
94#define _RT_STRING 0x00000010
95#define _RT_TABLE 0x00000020
96#define _RT_ARRAY 0x00000040
97#define _RT_USERDATA 0x00000080
98#define _RT_CLOSURE 0x00000100
99#define _RT_NATIVECLOSURE 0x00000200
100#define _RT_GENERATOR 0x00000400
101#define _RT_USERPOINTER 0x00000800
102#define _RT_THREAD 0x00001000
103#define _RT_FUNCPROTO 0x00002000
104#define _RT_CLASS 0x00004000
105#define _RT_INSTANCE 0x00008000
106#define _RT_WEAKREF 0x00010000
107#define _RT_OUTER 0x00020000
108
109typedef enum tagSQObjectType{
110 OT_NULL = (_RT_NULL|SQOBJECT_CANBEFALSE),
111 OT_INTEGER = (_RT_INTEGER|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
112 OT_FLOAT = (_RT_FLOAT|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
113 OT_BOOL = (_RT_BOOL|SQOBJECT_CANBEFALSE),
114 OT_STRING = (_RT_STRING|SQOBJECT_REF_COUNTED),
115 OT_TABLE = (_RT_TABLE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
116 OT_ARRAY = (_RT_ARRAY|SQOBJECT_REF_COUNTED),
117 OT_USERDATA = (_RT_USERDATA|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
118 OT_CLOSURE = (_RT_CLOSURE|SQOBJECT_REF_COUNTED),
119 OT_NATIVECLOSURE = (_RT_NATIVECLOSURE|SQOBJECT_REF_COUNTED),
120 OT_GENERATOR = (_RT_GENERATOR|SQOBJECT_REF_COUNTED),
121 OT_USERPOINTER = _RT_USERPOINTER,
122 OT_THREAD = (_RT_THREAD|SQOBJECT_REF_COUNTED) ,
123 OT_FUNCPROTO = (_RT_FUNCPROTO|SQOBJECT_REF_COUNTED), //internal usage only
124 OT_CLASS = (_RT_CLASS|SQOBJECT_REF_COUNTED),
125 OT_INSTANCE = (_RT_INSTANCE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
126 OT_WEAKREF = (_RT_WEAKREF|SQOBJECT_REF_COUNTED),
127 OT_OUTER = (_RT_OUTER|SQOBJECT_REF_COUNTED) //internal usage only
128}SQObjectType;
129
130#define ISREFCOUNTED(t) (t&SQOBJECT_REF_COUNTED)
131
132
133typedef union tagSQObjectValue
134{
135 struct SQTable *pTable;
136 struct SQArray *pArray;
137 struct SQClosure *pClosure;
138 struct SQOuter *pOuter;
139 struct SQGenerator *pGenerator;
140 struct SQNativeClosure *pNativeClosure;
141 struct SQString *pString;
142 struct SQUserData *pUserData;
143 SQInteger nInteger;
144 SQFloat fFloat;
145 SQUserPointer pUserPointer;
146 struct SQFunctionProto *pFunctionProto;
147 struct SQRefCounted *pRefCounted;
148 struct SQDelegable *pDelegable;
149 struct SQVM *pThread;
150 struct SQClass *pClass;
151 struct SQInstance *pInstance;
152 struct SQWeakRef *pWeakRef;
153 SQRawObjectVal raw;
154}SQObjectValue;
155
156
157typedef struct tagSQObject
158{
159 SQObjectType _type;
160 SQObjectValue _unVal;
161}SQObject;
162
163typedef struct tagSQMemberHandle{
164 SQBool _static;
165 SQInteger _index;
166}SQMemberHandle;
167
168typedef struct tagSQStackInfos{
169 const SQChar* funcname;
170 const SQChar* source;
171 SQInteger line;
172}SQStackInfos;
173
174typedef struct SQVM* HSQUIRRELVM;
175typedef SQObject HSQOBJECT;
176typedef SQMemberHandle HSQMEMBERHANDLE;
177typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
178typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size);
179typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/);
180typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
181typedef void (*SQDEBUGHOOK)(HSQUIRRELVM /*v*/, SQInteger /*type*/, const SQChar * /*sourcename*/, SQInteger /*line*/, const SQChar * /*funcname*/);
182typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
183typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
184
185typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
186
187typedef struct tagSQRegFunction{
188 const SQChar *name;
189 SQFUNCTION f;
190 SQInteger nparamscheck;
191 const SQChar *typemask;
192}SQRegFunction;
193
194typedef struct tagSQFunctionInfo {
195 SQUserPointer funcid;
196 const SQChar *name;
197 const SQChar *source;
198 SQInteger line;
199}SQFunctionInfo;
200
201/*vm*/
202SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
203SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
204SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
205SQUIRREL_API void sq_close(HSQUIRRELVM v);
206SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
207SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
208SQUIRREL_API void sq_setsharedforeignptr(HSQUIRRELVM v,SQUserPointer p);
209SQUIRREL_API SQUserPointer sq_getsharedforeignptr(HSQUIRRELVM v);
210SQUIRREL_API void sq_setvmreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook);
211SQUIRREL_API SQRELEASEHOOK sq_getvmreleasehook(HSQUIRRELVM v);
212SQUIRREL_API void sq_setsharedreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook);
213SQUIRREL_API SQRELEASEHOOK sq_getsharedreleasehook(HSQUIRRELVM v);
214SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc,SQPRINTFUNCTION errfunc);
215SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
216SQUIRREL_API SQPRINTFUNCTION sq_geterrorfunc(HSQUIRRELVM v);
217SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
218SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
219SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
220SQUIRREL_API SQInteger sq_getversion();
221
222/*compiler*/
223SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
224SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
225SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
226SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
227SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
228
229/*stack operations*/
230SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
231SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
232SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
233SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
234SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
235SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
236SQUIRREL_API SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
237SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
238SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
239
240/*object creation handling*/
241SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
242SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
243SQUIRREL_API void sq_newtableex(HSQUIRRELVM v,SQInteger initialcapacity);
244SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
245SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
246SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
247SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
248SQUIRREL_API SQRESULT sq_setclosureroot(HSQUIRRELVM v,SQInteger idx);
249SQUIRREL_API SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx);
250SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
251SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
252SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
253SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
254SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
255SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
256SQUIRREL_API void sq_pushthread(HSQUIRRELVM v, HSQUIRRELVM thread);
257SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
258SQUIRREL_API SQRESULT sq_typeof(HSQUIRRELVM v,SQInteger idx);
259SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
260SQUIRREL_API SQHash sq_gethash(HSQUIRRELVM v, SQInteger idx);
261SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
262SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
263SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx);
264SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
265SQUIRREL_API SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size);
266SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
267SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
268SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
269SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
270SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
271SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
272SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
273SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
274SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
275SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
276SQUIRREL_API SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx);
277SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
278SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi);
279SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars);
280SQUIRREL_API SQRESULT sq_getclosurename(HSQUIRRELVM v,SQInteger idx);
281SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
282SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
283SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
284SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
285SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
286SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
287SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
288SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
289SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
290SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
291SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
292SQUIRREL_API SQRESULT sq_getmemberhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
293SQUIRREL_API SQRESULT sq_getbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
294SQUIRREL_API SQRESULT sq_setbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
295
296/*object manipulation*/
297SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
298SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
299SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
300SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
301SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
302SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
303SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
304SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
305SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
306SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
307SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
308SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
309SQUIRREL_API SQRESULT sq_newmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
310SQUIRREL_API SQRESULT sq_rawnewmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
311SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
312SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
313SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
314SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
315SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
316SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
317SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
318SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
319SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
320SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
321SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
322SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
323SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
324
325/*calls*/
326SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
327SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
328SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
329SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v);
330SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
331SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
332SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
333SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
334SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
335SQUIRREL_API SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams);
336
337/*raw object handling*/
338SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
339SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
340SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
341SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
342SQUIRREL_API SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po);
343SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
344SQUIRREL_API const SQChar *sq_objtostring(const HSQOBJECT *o);
345SQUIRREL_API SQBool sq_objtobool(const HSQOBJECT *o);
346SQUIRREL_API SQInteger sq_objtointeger(const HSQOBJECT *o);
347SQUIRREL_API SQFloat sq_objtofloat(const HSQOBJECT *o);
348SQUIRREL_API SQUserPointer sq_objtouserpointer(const HSQOBJECT *o);
349SQUIRREL_API SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag);
350SQUIRREL_API SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM v, const HSQOBJECT *po);
351
352
353/*GC*/
354SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
355SQUIRREL_API SQRESULT sq_resurrectunreachable(HSQUIRRELVM v);
356
357/*serialization*/
358SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
359SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
360
361/*mem allocation*/
362SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
363SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
364SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
365
366/*debug*/
367SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
368SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
369SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
370
371/*UTILITY MACRO*/
372#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
373#define sq_istable(o) ((o)._type==OT_TABLE)
374#define sq_isarray(o) ((o)._type==OT_ARRAY)
375#define sq_isfunction(o) ((o)._type==OT_FUNCPROTO)
376#define sq_isclosure(o) ((o)._type==OT_CLOSURE)
377#define sq_isgenerator(o) ((o)._type==OT_GENERATOR)
378#define sq_isnativeclosure(o) ((o)._type==OT_NATIVECLOSURE)
379#define sq_isstring(o) ((o)._type==OT_STRING)
380#define sq_isinteger(o) ((o)._type==OT_INTEGER)
381#define sq_isfloat(o) ((o)._type==OT_FLOAT)
382#define sq_isuserpointer(o) ((o)._type==OT_USERPOINTER)
383#define sq_isuserdata(o) ((o)._type==OT_USERDATA)
384#define sq_isthread(o) ((o)._type==OT_THREAD)
385#define sq_isnull(o) ((o)._type==OT_NULL)
386#define sq_isclass(o) ((o)._type==OT_CLASS)
387#define sq_isinstance(o) ((o)._type==OT_INSTANCE)
388#define sq_isbool(o) ((o)._type==OT_BOOL)
389#define sq_isweakref(o) ((o)._type==OT_WEAKREF)
390#define sq_type(o) ((o)._type)
391
392/* deprecated */
393#define sq_createslot(v,n) sq_newslot(v,n,SQFalse)
394
395#define SQ_OK (0)
396#define SQ_ERROR (-1)
397
398#define SQ_FAILED(res) (res<0)
399#define SQ_SUCCEEDED(res) (res>=0)
400
401#ifdef __GNUC__
402# define SQ_UNUSED_ARG(x) x __attribute__((__unused__))
403#else
404# define SQ_UNUSED_ARG(x) x
405#endif
406
407#ifdef __cplusplus
408} /*extern "C"*/
409#endif
410
411#endif /*_SQUIRREL_H_*/
412