Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 lines
17 KiB

  1. /*
  2. Copyright (c) 2003-2009 Alberto Demichelis
  3. This software is provided 'as-is', without any
  4. express or implied warranty. In no event will the
  5. authors be held liable for any damages arising from
  6. the use of this software.
  7. Permission is granted to anyone to use this software
  8. for any purpose, including commercial applications,
  9. and to alter it and redistribute it freely, subject
  10. to the following restrictions:
  11. 1. The origin of this software must not be
  12. misrepresented; you must not claim that
  13. you wrote the original software. If you
  14. use this software in a product, an
  15. acknowledgment in the product
  16. documentation would be appreciated but is
  17. not required.
  18. 2. Altered source versions must be plainly
  19. marked as such, and must not be
  20. misrepresented as being the original
  21. software.
  22. 3. This notice may not be removed or
  23. altered from any source distribution.
  24. */
  25. #ifndef _SQUIRREL_H_
  26. #define _SQUIRREL_H_
  27. #if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
  28. #include "platform.h"
  29. #include "dbg.h"
  30. #if defined(VSQUIRREL_TEST)
  31. #define printf( fmt, ...) Msg( fmt, ##__VA_ARGS__ );
  32. #else
  33. #define printf( fmt, ...) DevMsg( fmt, ##__VA_ARGS__ );
  34. #endif
  35. #else
  36. #define Assert assert
  37. #endif
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #ifndef SQUIRREL_API
  42. #define SQUIRREL_API extern
  43. #endif
  44. #ifdef PLATFORM_64BITS
  45. #define _SQ64
  46. #endif
  47. #ifdef _SQ64
  48. #define SQUSEDOUBLE
  49. typedef int64 SQInteger;
  50. typedef uint64 SQUnsignedInteger;
  51. typedef uint64 SQHash; /*should be the same size of a pointer*/
  52. typedef int SQInt32;
  53. #else
  54. typedef int SQInteger;
  55. typedef int SQInt32; /*must be 32 bits(also on 64bits processors)*/
  56. typedef unsigned int SQUnsignedInteger;
  57. typedef unsigned int SQHash; /*should be the same size of a pointer*/
  58. #endif
  59. #ifdef SQUSEDOUBLE
  60. typedef double SQFloat;
  61. #else
  62. typedef float SQFloat;
  63. #endif
  64. #if defined(SQUSEDOUBLE) && !defined(_SQ64)
  65. #ifdef _MSC_VER
  66. typedef __int64 SQRawObjectVal; //must be 64bits
  67. #else
  68. typedef long SQRawObjectVal; //must be 64bits
  69. #endif
  70. #define SQ_OBJECT_RAWINIT() { _unVal.raw = 0; }
  71. #else
  72. typedef SQUnsignedInteger SQRawObjectVal; //is 32 bits on 32 bits builds and 64 bits otherwise
  73. #define SQ_OBJECT_RAWINIT()
  74. #endif
  75. typedef void* SQUserPointer;
  76. typedef SQUnsignedInteger SQBool;
  77. typedef SQInteger SQRESULT;
  78. #define SQTrue (1)
  79. #define SQFalse (0)
  80. struct SQVM;
  81. struct SQTable;
  82. struct SQArray;
  83. struct SQString;
  84. struct SQClosure;
  85. struct SQGenerator;
  86. struct SQNativeClosure;
  87. struct SQUserData;
  88. struct SQFunctionProto;
  89. struct SQRefCounted;
  90. struct SQClass;
  91. struct SQInstance;
  92. struct SQDelegable;
  93. #ifdef _UNICODE
  94. #define SQUNICODE
  95. #endif
  96. #ifdef SQUNICODE
  97. #if (defined(_MSC_VER) && _MSC_VER >= 1400) // 1400 = VS8
  98. #if defined(wchar_t) //this is if the compiler considers wchar_t as native type
  99. #define wchar_t unsigned short
  100. #endif
  101. #else
  102. typedef unsigned short wchar_t;
  103. #endif
  104. typedef wchar_t SQChar;
  105. #define _SC(a) L##a
  106. #define scstrcmp wcscmp
  107. #define scsprintf swprintf
  108. #define scstrlen wcslen
  109. #define scstrtod wcstod
  110. #define scstrtol wcstol
  111. #define scatoi _wtoi
  112. #define scstrtoul wcstoul
  113. #define scvsprintf vswprintf
  114. #define scstrstr wcsstr
  115. #define scisspace iswspace
  116. #define scisdigit iswdigit
  117. #define scisxdigit iswxdigit
  118. #define scisalpha iswalpha
  119. #define sciscntrl iswcntrl
  120. #define scisalnum iswalnum
  121. #define scprintf wprintf
  122. #define MAX_CHAR 0xFFFF
  123. #else
  124. typedef char SQChar;
  125. #define _SC(a) a
  126. #define scstrcmp strcmp
  127. #define scsprintf sprintf
  128. #define scstrlen strlen
  129. #define scstrtod strtod
  130. #define scstrtol strtol
  131. #define scatoi atoi
  132. #define scstrtoul strtoul
  133. #define scvsprintf vsprintf
  134. #define scstrstr strstr
  135. #define scisspace isspace
  136. #define scisdigit isdigit
  137. #define scisxdigit isxdigit
  138. #define sciscntrl iscntrl
  139. #define scisalpha isalpha
  140. #define scisalnum isalnum
  141. #define scprintf printf
  142. #define MAX_CHAR 0xFF
  143. #endif
  144. #define SQUIRREL_VERSION _SC("Squirrel 2.2.3 stable")
  145. #define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2009 Alberto Demichelis")
  146. #define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
  147. #define SQ_VMSTATE_IDLE 0
  148. #define SQ_VMSTATE_RUNNING 1
  149. #define SQ_VMSTATE_SUSPENDED 2
  150. #define SQUIRREL_EOB 0
  151. #define SQ_BYTECODE_STREAM_TAG 0xFAFA
  152. #define SQOBJECT_REF_COUNTED 0x08000000
  153. #define SQOBJECT_NUMERIC 0x04000000
  154. #define SQOBJECT_DELEGABLE 0x02000000
  155. #define SQOBJECT_CANBEFALSE 0x01000000
  156. #define SQ_MATCHTYPEMASKSTRING (-99999)
  157. #define _RT_MASK 0x00FFFFFF
  158. #define _RAW_TYPE(type) (type&_RT_MASK)
  159. #define _RT_NULL 0x00000001
  160. #define _RT_INTEGER 0x00000002
  161. #define _RT_FLOAT 0x00000004
  162. #define _RT_BOOL 0x00000008
  163. #define _RT_STRING 0x00000010
  164. #define _RT_TABLE 0x00000020
  165. #define _RT_ARRAY 0x00000040
  166. #define _RT_USERDATA 0x00000080
  167. #define _RT_CLOSURE 0x00000100
  168. #define _RT_NATIVECLOSURE 0x00000200
  169. #define _RT_GENERATOR 0x00000400
  170. #define _RT_USERPOINTER 0x00000800
  171. #define _RT_THREAD 0x00001000
  172. #define _RT_FUNCPROTO 0x00002000
  173. #define _RT_CLASS 0x00004000
  174. #define _RT_INSTANCE 0x00008000
  175. #define _RT_WEAKREF 0x00010000
  176. typedef enum tagSQObjectType{
  177. OT_NULL = (_RT_NULL|SQOBJECT_CANBEFALSE),
  178. OT_INTEGER = (_RT_INTEGER|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
  179. OT_FLOAT = (_RT_FLOAT|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
  180. OT_BOOL = (_RT_BOOL|SQOBJECT_CANBEFALSE),
  181. OT_STRING = (_RT_STRING|SQOBJECT_REF_COUNTED),
  182. OT_TABLE = (_RT_TABLE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
  183. OT_ARRAY = (_RT_ARRAY|SQOBJECT_REF_COUNTED),
  184. OT_USERDATA = (_RT_USERDATA|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
  185. OT_CLOSURE = (_RT_CLOSURE|SQOBJECT_REF_COUNTED),
  186. OT_NATIVECLOSURE = (_RT_NATIVECLOSURE|SQOBJECT_REF_COUNTED),
  187. OT_GENERATOR = (_RT_GENERATOR|SQOBJECT_REF_COUNTED),
  188. OT_USERPOINTER = _RT_USERPOINTER,
  189. OT_THREAD = (_RT_THREAD|SQOBJECT_REF_COUNTED) ,
  190. OT_FUNCPROTO = (_RT_FUNCPROTO|SQOBJECT_REF_COUNTED), //internal usage only
  191. OT_CLASS = (_RT_CLASS|SQOBJECT_REF_COUNTED),
  192. OT_INSTANCE = (_RT_INSTANCE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
  193. OT_WEAKREF = (_RT_WEAKREF|SQOBJECT_REF_COUNTED)
  194. }SQObjectType;
  195. #define ISREFCOUNTED(t) (t&SQOBJECT_REF_COUNTED)
  196. typedef union tagSQObjectValue
  197. {
  198. struct SQTable *pTable;
  199. struct SQArray *pArray;
  200. struct SQClosure *pClosure;
  201. struct SQGenerator *pGenerator;
  202. struct SQNativeClosure *pNativeClosure;
  203. struct SQString *pString;
  204. struct SQUserData *pUserData;
  205. SQInteger nInteger;
  206. SQFloat fFloat;
  207. SQUserPointer pUserPointer;
  208. struct SQFunctionProto *pFunctionProto;
  209. struct SQRefCounted *pRefCounted;
  210. struct SQDelegable *pDelegable;
  211. struct SQVM *pThread;
  212. struct SQClass *pClass;
  213. struct SQInstance *pInstance;
  214. struct SQWeakRef *pWeakRef;
  215. SQRawObjectVal raw;
  216. }SQObjectValue;
  217. typedef struct tagSQObject
  218. {
  219. SQObjectType _type;
  220. SQObjectValue _unVal;
  221. }SQObject;
  222. typedef struct tagSQStackInfos{
  223. const SQChar* funcname;
  224. const SQChar* source;
  225. SQInteger line;
  226. }SQStackInfos;
  227. typedef struct SQVM* HSQUIRRELVM;
  228. typedef SQObject HSQOBJECT;
  229. typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
  230. typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size);
  231. typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/);
  232. typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
  233. typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
  234. typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
  235. typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
  236. typedef struct tagSQRegFunction{
  237. const SQChar *name;
  238. SQFUNCTION f;
  239. SQInteger nparamscheck;
  240. const SQChar *typemask;
  241. }SQRegFunction;
  242. typedef struct tagSQFunctionInfo {
  243. SQUserPointer funcid;
  244. const SQChar *name;
  245. const SQChar *source;
  246. }SQFunctionInfo;
  247. /*vm*/
  248. SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
  249. SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
  250. SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
  251. SQUIRREL_API void sq_close(HSQUIRRELVM v);
  252. SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
  253. SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
  254. SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
  255. SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
  256. SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
  257. SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
  258. SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
  259. /*compiler*/
  260. SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
  261. SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
  262. SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
  263. SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
  264. SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
  265. /*stack operations*/
  266. SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
  267. SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
  268. SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
  269. SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
  270. SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
  271. SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
  272. SQUIRREL_API void sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
  273. SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
  274. SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
  275. /*object creation handling*/
  276. SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
  277. SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
  278. SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
  279. SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
  280. SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
  281. SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
  282. SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
  283. SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
  284. SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
  285. SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
  286. SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
  287. SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
  288. SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
  289. SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
  290. SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
  291. SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
  292. SQUIRREL_API void sq_tostring(HSQUIRRELVM v,SQInteger idx);
  293. SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
  294. SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
  295. SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
  296. SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
  297. SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
  298. SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
  299. SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
  300. SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
  301. SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
  302. SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
  303. SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
  304. SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
  305. SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger idx,SQFunctionInfo *fi);
  306. SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
  307. SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
  308. SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
  309. SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
  310. SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
  311. SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
  312. SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
  313. SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
  314. SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
  315. SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
  316. SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
  317. SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
  318. /*object manipulation*/
  319. SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
  320. SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
  321. SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
  322. SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
  323. SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
  324. SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
  325. SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  326. SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
  327. SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
  328. SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
  329. SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
  330. SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  331. SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
  332. SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  333. SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
  334. SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
  335. SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
  336. SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
  337. SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
  338. SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
  339. SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
  340. SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
  341. SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
  342. SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
  343. SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
  344. /*calls*/
  345. SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
  346. SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
  347. SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
  348. SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
  349. SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
  350. SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
  351. SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
  352. /*raw object handling*/
  353. SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
  354. SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
  355. SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
  356. SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
  357. SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
  358. SQUIRREL_API const SQChar *sq_objtostring(HSQOBJECT *o);
  359. SQUIRREL_API SQBool sq_objtobool(HSQOBJECT *o);
  360. SQUIRREL_API SQInteger sq_objtointeger(HSQOBJECT *o);
  361. SQUIRREL_API SQFloat sq_objtofloat(HSQOBJECT *o);
  362. SQUIRREL_API SQRESULT sq_getobjtypetag(HSQOBJECT *o,SQUserPointer * typetag);
  363. /*GC*/
  364. SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
  365. /*serialization*/
  366. SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
  367. SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
  368. #if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
  369. #define sq_malloc malloc
  370. #define sq_realloc(p,oldsize,size) realloc(p, size)
  371. #define sq_free(p,size) free(p)
  372. #else
  373. /*mem allocation*/
  374. SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
  375. SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
  376. SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
  377. #endif
  378. /*debug*/
  379. SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
  380. SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
  381. /*UTILITY MACRO*/
  382. #define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
  383. #define sq_istable(o) ((o)._type==OT_TABLE)
  384. #define sq_isarray(o) ((o)._type==OT_ARRAY)
  385. #define sq_isfunction(o) ((o)._type==OT_FUNCPROTO)
  386. #define sq_isclosure(o) ((o)._type==OT_CLOSURE)
  387. #define sq_isgenerator(o) ((o)._type==OT_GENERATOR)
  388. #define sq_isnativeclosure(o) ((o)._type==OT_NATIVECLOSURE)
  389. #define sq_isstring(o) ((o)._type==OT_STRING)
  390. #define sq_isinteger(o) ((o)._type==OT_INTEGER)
  391. #define sq_isfloat(o) ((o)._type==OT_FLOAT)
  392. #define sq_isuserpointer(o) ((o)._type==OT_USERPOINTER)
  393. #define sq_isuserdata(o) ((o)._type==OT_USERDATA)
  394. #define sq_isthread(o) ((o)._type==OT_THREAD)
  395. #define sq_isnull(o) ((o)._type==OT_NULL)
  396. #define sq_isclass(o) ((o)._type==OT_CLASS)
  397. #define sq_isinstance(o) ((o)._type==OT_INSTANCE)
  398. #define sq_isbool(o) ((o)._type==OT_BOOL)
  399. #define sq_isweakref(o) ((o)._type==OT_WEAKREF)
  400. #define sq_type(o) ((o)._type)
  401. /* deprecated */
  402. #define sq_createslot(v,n) sq_newslot(v,n,SQFalse)
  403. #define SQ_OK (0)
  404. #define SQ_ERROR (-1)
  405. #define SQ_FAILED(res) (res<0)
  406. #define SQ_SUCCEEDED(res) (res>=0)
  407. #ifdef __cplusplus
  408. } /*extern "C"*/
  409. #endif
  410. #endif /*_SQUIRREL_H_*/