1 | /* |
2 | Copyright (c) 2003-2017 Alberto Demichelis |
3 | |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | of this software and associated documentation files (the "Software"), to deal |
6 | in the Software without restriction, including without limitation the rights |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
8 | copies of the Software, and to permit persons to whom the Software is |
9 | furnished to do so, subject to the following conditions: |
10 | |
11 | The above copyright notice and this permission notice shall be included in |
12 | all copies or substantial portions of the Software. |
13 | |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20 | THE 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 |
30 | extern "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 | |
47 | struct SQVM; |
48 | struct SQTable; |
49 | struct SQArray; |
50 | struct SQString; |
51 | struct SQClosure; |
52 | struct SQGenerator; |
53 | struct SQNativeClosure; |
54 | struct SQUserData; |
55 | struct SQFunctionProto; |
56 | struct SQRefCounted; |
57 | struct SQClass; |
58 | struct SQInstance; |
59 | struct SQDelegable; |
60 | struct 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 | |
109 | typedef 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 | |
133 | typedef 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 | |
157 | typedef struct tagSQObject |
158 | { |
159 | SQObjectType _type; |
160 | SQObjectValue _unVal; |
161 | }SQObject; |
162 | |
163 | typedef struct tagSQMemberHandle{ |
164 | SQBool _static; |
165 | SQInteger _index; |
166 | }SQMemberHandle; |
167 | |
168 | typedef struct tagSQStackInfos{ |
169 | const SQChar* funcname; |
170 | const SQChar* source; |
171 | SQInteger line; |
172 | }SQStackInfos; |
173 | |
174 | typedef struct SQVM* HSQUIRRELVM; |
175 | typedef SQObject HSQOBJECT; |
176 | typedef SQMemberHandle HSQMEMBERHANDLE; |
177 | typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM); |
178 | typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size); |
179 | typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/); |
180 | typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...); |
181 | typedef void (*SQDEBUGHOOK)(HSQUIRRELVM /*v*/, SQInteger /*type*/, const SQChar * /*sourcename*/, SQInteger /*line*/, const SQChar * /*funcname*/); |
182 | typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger); |
183 | typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger); |
184 | |
185 | typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer); |
186 | |
187 | typedef struct tagSQRegFunction{ |
188 | const SQChar *name; |
189 | SQFUNCTION f; |
190 | SQInteger nparamscheck; |
191 | const SQChar *typemask; |
192 | }SQRegFunction; |
193 | |
194 | typedef struct tagSQFunctionInfo { |
195 | SQUserPointer funcid; |
196 | const SQChar *name; |
197 | const SQChar *source; |
198 | SQInteger line; |
199 | }SQFunctionInfo; |
200 | |
201 | /*vm*/ |
202 | SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize); |
203 | SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize); |
204 | SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v); |
205 | SQUIRREL_API void sq_close(HSQUIRRELVM v); |
206 | SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p); |
207 | SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v); |
208 | SQUIRREL_API void sq_setsharedforeignptr(HSQUIRRELVM v,SQUserPointer p); |
209 | SQUIRREL_API SQUserPointer sq_getsharedforeignptr(HSQUIRRELVM v); |
210 | SQUIRREL_API void sq_setvmreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook); |
211 | SQUIRREL_API SQRELEASEHOOK sq_getvmreleasehook(HSQUIRRELVM v); |
212 | SQUIRREL_API void sq_setsharedreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook); |
213 | SQUIRREL_API SQRELEASEHOOK sq_getsharedreleasehook(HSQUIRRELVM v); |
214 | SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc,SQPRINTFUNCTION errfunc); |
215 | SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v); |
216 | SQUIRREL_API SQPRINTFUNCTION sq_geterrorfunc(HSQUIRRELVM v); |
217 | SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v); |
218 | SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror); |
219 | SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v); |
220 | SQUIRREL_API SQInteger sq_getversion(); |
221 | |
222 | /*compiler*/ |
223 | SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror); |
224 | SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror); |
225 | SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable); |
226 | SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable); |
227 | SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f); |
228 | |
229 | /*stack operations*/ |
230 | SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx); |
231 | SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop); |
232 | SQUIRREL_API void sq_poptop(HSQUIRRELVM v); |
233 | SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx); |
234 | SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v); |
235 | SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop); |
236 | SQUIRREL_API SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize); |
237 | SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v); |
238 | SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx); |
239 | |
240 | /*object creation handling*/ |
241 | SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size); |
242 | SQUIRREL_API void sq_newtable(HSQUIRRELVM v); |
243 | SQUIRREL_API void sq_newtableex(HSQUIRRELVM v,SQInteger initialcapacity); |
244 | SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size); |
245 | SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars); |
246 | SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask); |
247 | SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx); |
248 | SQUIRREL_API SQRESULT sq_setclosureroot(HSQUIRRELVM v,SQInteger idx); |
249 | SQUIRREL_API SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx); |
250 | SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len); |
251 | SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f); |
252 | SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n); |
253 | SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b); |
254 | SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p); |
255 | SQUIRREL_API void sq_pushnull(HSQUIRRELVM v); |
256 | SQUIRREL_API void sq_pushthread(HSQUIRRELVM v, HSQUIRRELVM thread); |
257 | SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx); |
258 | SQUIRREL_API SQRESULT sq_typeof(HSQUIRRELVM v,SQInteger idx); |
259 | SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx); |
260 | SQUIRREL_API SQHash sq_gethash(HSQUIRRELVM v, SQInteger idx); |
261 | SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx); |
262 | SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v); |
263 | SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx); |
264 | SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b); |
265 | SQUIRREL_API SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size); |
266 | SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c); |
267 | SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i); |
268 | SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f); |
269 | SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b); |
270 | SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread); |
271 | SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p); |
272 | SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag); |
273 | SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag); |
274 | SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag); |
275 | SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook); |
276 | SQUIRREL_API SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx); |
277 | SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize); |
278 | SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi); |
279 | SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars); |
280 | SQUIRREL_API SQRESULT sq_getclosurename(HSQUIRRELVM v,SQInteger idx); |
281 | SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name); |
282 | SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p); |
283 | SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag); |
284 | SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize); |
285 | SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase); |
286 | SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx); |
287 | SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx); |
288 | SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx); |
289 | SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx); |
290 | SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx); |
291 | SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t); |
292 | SQUIRREL_API SQRESULT sq_getmemberhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle); |
293 | SQUIRREL_API SQRESULT sq_getbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle); |
294 | SQUIRREL_API SQRESULT sq_setbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle); |
295 | |
296 | /*object manipulation*/ |
297 | SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v); |
298 | SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v); |
299 | SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v); |
300 | SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v); |
301 | SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v); |
302 | SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic); |
303 | SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval); |
304 | SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx); |
305 | SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx); |
306 | SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx); |
307 | SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx); |
308 | SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval); |
309 | SQUIRREL_API SQRESULT sq_newmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic); |
310 | SQUIRREL_API SQRESULT sq_rawnewmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic); |
311 | SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx); |
312 | SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval); |
313 | SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize); |
314 | SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx); |
315 | SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx); |
316 | SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos); |
317 | SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx); |
318 | SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx); |
319 | SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx); |
320 | SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval); |
321 | SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx); |
322 | SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx); |
323 | SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx); |
324 | |
325 | /*calls*/ |
326 | SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror); |
327 | SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror); |
328 | SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx); |
329 | SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v); |
330 | SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval); |
331 | SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err); |
332 | SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v); |
333 | SQUIRREL_API void sq_reseterror(HSQUIRRELVM v); |
334 | SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v); |
335 | SQUIRREL_API SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams); |
336 | |
337 | /*raw object handling*/ |
338 | SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po); |
339 | SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj); |
340 | SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po); |
341 | SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po); |
342 | SQUIRREL_API SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po); |
343 | SQUIRREL_API void sq_resetobject(HSQOBJECT *po); |
344 | SQUIRREL_API const SQChar *sq_objtostring(const HSQOBJECT *o); |
345 | SQUIRREL_API SQBool sq_objtobool(const HSQOBJECT *o); |
346 | SQUIRREL_API SQInteger sq_objtointeger(const HSQOBJECT *o); |
347 | SQUIRREL_API SQFloat sq_objtofloat(const HSQOBJECT *o); |
348 | SQUIRREL_API SQUserPointer sq_objtouserpointer(const HSQOBJECT *o); |
349 | SQUIRREL_API SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag); |
350 | SQUIRREL_API SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM v, const HSQOBJECT *po); |
351 | |
352 | |
353 | /*GC*/ |
354 | SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v); |
355 | SQUIRREL_API SQRESULT sq_resurrectunreachable(HSQUIRRELVM v); |
356 | |
357 | /*serialization*/ |
358 | SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up); |
359 | SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up); |
360 | |
361 | /*mem allocation*/ |
362 | SQUIRREL_API void *sq_malloc(SQUnsignedInteger size); |
363 | SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize); |
364 | SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size); |
365 | |
366 | /*debug*/ |
367 | SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si); |
368 | SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v); |
369 | SQUIRREL_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 | |