squirrel.h 18 KB

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