# squirrel.h

    00001 /*
    00002 Copyright (c) 2003-2008 Alberto Demichelis
    00003
    00004 This software is provided 'as-is', without any
    00005 express or implied warranty. In no event will the
    00006 authors be held liable for any damages arising from
    00007 the use of this software.
    00008
    00009 Permission is granted to anyone to use this software
    00010 for any purpose, including commercial applications,
    00011 and to alter it and redistribute it freely, subject
    00012 to the following restrictions:
    00013
    00014     1. The origin of this software must not be
    00015     misrepresented; you must not claim that
    00016     you wrote the original software. If you
    00017     use this software in a product, an
    00018     acknowledgment in the product
    00019     documentation would be appreciated but is
    00020     not required.
    00021
    00022     2. Altered source versions must be plainly
    00023     marked as such, and must not be
    00024     misrepresented as being the original
    00025     software.
    00026
    00027     3. This notice may not be removed or
    00028     altered from any source distribution.
    00029
    00030 */
    00031 #ifndef _SQUIRREL_H_
    00032 #define _SQUIRREL_H_
    00033
    00034 #ifdef __cplusplus
    00035 extern "C" {
    00036 #endif
    00037
    00038 #if defined(_MSC_VER) && _MSC_VER >= 1400 // MSVC 2005 safety checks
    00039 # pragma warning(disable: 4996)   // '_wfopen' was declared deprecated
    00040 # define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
    00041 # define _CRT_NON_CONFORMING_SWPRINTFS // another deprecated stuff
    00042 #endif /* _MSC_VER >= 1400 */
    00043
    00044 #ifndef SQUIRREL_API
    00045 #define SQUIRREL_API extern
    00046 #endif
    00047
    00048 #if (defined(_WIN64) || defined(_LP64)) && !defined(_SQ64)
    00049 #define _SQ64
    00050 #endif
    00051
    00052 #ifdef _SQ64
    00053 #ifdef _MSC_VER
    00054 typedef __int64 SQInteger;
    00055 typedef unsigned __int64 SQUnsignedInteger;
    00056 typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
    00057 #else
    00058 typedef long SQInteger;
    00059 typedef unsigned long SQUnsignedInteger;
    00060 typedef unsigned long SQHash; /*should be the same size of a pointer*/
    00061 #endif
    00062 typedef int SQInt32;
    00063 #else
    00064 typedef int SQInteger;
    00065 typedef int SQInt32; /*must be 32 bits(also on 64bits processors)*/
    00066 typedef unsigned int SQUnsignedInteger;
    00067 typedef unsigned int SQHash; /*should be the same size of a pointer*/
    00068 #endif
    00069
    00070
    00071 typedef float SQFloat;
    00072 typedef void* SQUserPointer;
    00073 typedef SQUnsignedInteger SQBool;
    00074 typedef SQInteger SQRESULT;
    00075
    00076 #define SQTrue  (1)
    00077 #define SQFalse (0)
    00078
    00079 struct SQVM;
    00080 struct SQTable;
    00081 struct SQArray;
    00082 struct SQString;
    00083 struct SQClosure;
    00084 struct SQGenerator;
    00085 struct SQNativeClosure;
    00086 struct SQUserData;
    00087 struct SQFunctionProto;
    00088 struct SQRefCounted;
    00089 struct SQClass;
    00090 struct SQInstance;
    00091 struct SQDelegable;
    00092
    00093 #ifdef _UNICODE
    00094 #define SQUNICODE
    00095 #endif
    00096
    00097 #ifdef SQUNICODE
    00098 #if (defined(_MSC_VER) && _MSC_VER >= 1400) // 1400 = VS8
    00099
    00100 #ifndef _WCHAR_T_DEFINED //this is if the compiler considers wchar_t as native type
    00101 typedef unsigned short wchar_t;
    00102 #endif
    00103 #endif
    00104
    00105 typedef wchar_t SQChar;
    00106 #define _SC(a) L##a
    00107 #define scstrcmp  wcscmp
    00108 #define scsprintf swprintf
    00109 #define scsnprintf  _snwprintf
    00110 #define scstrlen  wcslen
    00111 #define scstrtod  wcstod
    00112 #define scstrtol  wcstol
    00113 #define scatoi    _wtoi
    00114 #define scstrtoul wcstoul
    00115 #define scvsprintf  vswprintf
    00116 #define scstrstr  wcsstr
    00117 #define scisspace iswspace
    00118 #define scisdigit iswdigit
    00119 #define scisxdigit  iswxdigit
    00120 #define scisalpha iswalpha
    00121 #define sciscntrl iswcntrl
    00122 #define scisalnum iswalnum
    00123 #define scprintf  wprintf
    00124 #define scfprintf fwprintf
    00125 #define scvprintf vwprintf
    00126 #define scvfprintf  vfwprintf
    00127 #define scvsnprintf _vsnwprintf
    00128 #define scstrdup  _wcsdup
    00129 #define scstrrchr wcsrchr
    00130 #define scstrcat  wcscat
    00131 #define MAX_CHAR 0xFFFF
    00132 #else
    00133 typedef char SQChar;
    00134 #define _SC(a) a
    00135 #define scstrcmp  strcmp
    00136 #define scsprintf sprintf
    00137 #define scsnprintf  snprintf
    00138 #define scstrlen  strlen
    00139 #define scstrtod  strtod
    00140 #define scstrtol  strtol
    00141 #define scatoi    atoi
    00142 #define scstrtoul strtoul
    00143 #define scvsprintf  vsprintf
    00144 #define scstrstr  strstr
    00145 #define scisspace isspace
    00146 #define scisdigit isdigit
    00147 #define scisxdigit  isxdigit
    00148 #define sciscntrl iscntrl
    00149 #define scisalpha isalpha
    00150 #define scisalnum isalnum
    00151 #define scprintf  printf
    00152 #define scfprintf fprintf
    00153 #define scvprintf vprintf
    00154 #define scvfprintf  vfprintf
    00155 #define scvsnprintf vsnprintf
    00156 #define scstrdup  strdup
    00157 #define scstrrchr strrchr
    00158 #define scstrcat  strcat
    00159 #define MAX_CHAR 0xFF
    00160 #endif
    00161
    00162 #define SQUIRREL_VERSION  _SC("Squirrel 2.2.2 stable - With custom OpenTTD modifications")
    00163 #define SQUIRREL_COPYRIGHT  _SC("Copyright (C) 2003-2008 Alberto Demichelis")
    00164 #define SQUIRREL_AUTHOR   _SC("Alberto Demichelis")
    00165
    00166 #define SQ_VMSTATE_IDLE     0
    00167 #define SQ_VMSTATE_RUNNING    1
    00168 #define SQ_VMSTATE_SUSPENDED  2
    00169
    00170 #define SQUIRREL_EOB 0
    00171 #define SQ_BYTECODE_STREAM_TAG  0xFAFA
    00172
    00173 #define SQOBJECT_REF_COUNTED  0x08000000
    00174 #define SQOBJECT_NUMERIC    0x04000000
    00175 #define SQOBJECT_DELEGABLE    0x02000000
    00176 #define SQOBJECT_CANBEFALSE   0x01000000
    00177
    00178 #define SQ_MATCHTYPEMASKSTRING (-99999)
    00179
    00180 #define _RT_MASK 0x00FFFFFF
    00181 #define _RAW_TYPE(type) (type&_RT_MASK)
    00182
    00183 #define _RT_NULL      0x00000001
    00184 #define _RT_INTEGER     0x00000002
    00185 #define _RT_FLOAT     0x00000004
    00186 #define _RT_BOOL      0x00000008
    00187 #define _RT_STRING      0x00000010
    00188 #define _RT_TABLE     0x00000020
    00189 #define _RT_ARRAY     0x00000040
    00190 #define _RT_USERDATA    0x00000080
    00191 #define _RT_CLOSURE     0x00000100
    00192 #define _RT_NATIVECLOSURE 0x00000200
    00193 #define _RT_GENERATOR   0x00000400
    00194 #define _RT_USERPOINTER   0x00000800
    00195 #define _RT_THREAD      0x00001000
    00196 #define _RT_FUNCPROTO   0x00002000
    00197 #define _RT_CLASS     0x00004000
    00198 #define _RT_INSTANCE    0x00008000
    00199 #define _RT_WEAKREF     0x00010000
    00200
    00201 typedef enum tagSQObjectType{
    00202   OT_NULL =     (_RT_NULL|SQOBJECT_CANBEFALSE),
    00203   OT_INTEGER =    (_RT_INTEGER|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
    00204   OT_FLOAT =      (_RT_FLOAT|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
    00205   OT_BOOL =     (_RT_BOOL|SQOBJECT_CANBEFALSE),
    00206   OT_STRING =     (_RT_STRING|SQOBJECT_REF_COUNTED),
    00207   OT_TABLE =      (_RT_TABLE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
    00208   OT_ARRAY =      (_RT_ARRAY|SQOBJECT_REF_COUNTED),
    00209   OT_USERDATA =   (_RT_USERDATA|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
    00210   OT_CLOSURE =    (_RT_CLOSURE|SQOBJECT_REF_COUNTED),
    00211   OT_NATIVECLOSURE =  (_RT_NATIVECLOSURE|SQOBJECT_REF_COUNTED),
    00212   OT_GENERATOR =    (_RT_GENERATOR|SQOBJECT_REF_COUNTED),
    00213   OT_USERPOINTER =  _RT_USERPOINTER,
    00214   OT_THREAD =     (_RT_THREAD|SQOBJECT_REF_COUNTED) ,
    00215   OT_FUNCPROTO =    (_RT_FUNCPROTO|SQOBJECT_REF_COUNTED), //internal usage only
    00216   OT_CLASS =      (_RT_CLASS|SQOBJECT_REF_COUNTED),
    00217   OT_INSTANCE =   (_RT_INSTANCE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
    00218   OT_WEAKREF =    (_RT_WEAKREF|SQOBJECT_REF_COUNTED)
    00219 }SQObjectType;
    00220
    00221 #define ISREFCOUNTED(t) (t&SQOBJECT_REF_COUNTED)
    00222
    00223
    00224 typedef union tagSQObjectValue
    00225 {
    00226   struct SQTable *pTable;
    00227   struct SQArray *pArray;
    00228   struct SQClosure *pClosure;
    00229   struct SQGenerator *pGenerator;
    00230   struct SQNativeClosure *pNativeClosure;
    00231   struct SQString *pString;
    00232   struct SQUserData *pUserData;
    00233   SQInteger nInteger;
    00234   SQFloat fFloat;
    00235   SQUserPointer pUserPointer;
    00236   struct SQFunctionProto *pFunctionProto;
    00237   struct SQRefCounted *pRefCounted;
    00238   struct SQDelegable *pDelegable;
    00239   struct SQVM *pThread;
    00240   struct SQClass *pClass;
    00241   struct SQInstance *pInstance;
    00242   struct SQWeakRef *pWeakRef;
    00243 }SQObjectValue;
    00244
    00245
    00246 typedef struct tagSQObject
    00247 {
    00248   SQObjectType _type;
    00249   SQObjectValue _unVal;
    00250 }SQObject;
    00251
    00252 typedef struct tagSQStackInfos{
    00253   const SQChar* funcname;
    00254   const SQChar* source;
    00255   SQInteger line;
    00256 }SQStackInfos;
    00257
    00258 typedef struct SQVM* HSQUIRRELVM;
    00259 typedef SQObject HSQOBJECT;
    00260 typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
    00261 typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size);
    00262 typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/);
    00263 typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
    00264
    00265 typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
    00266 typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
    00267
    00268 typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
    00269
    00270 typedef struct tagSQRegFunction{
    00271   const SQChar *name;
    00272   SQFUNCTION f;
    00273   SQInteger nparamscheck;
    00274   const SQChar *typemask;
    00275 }SQRegFunction;
    00276
    00277 /*vm*/
    00278 SQUIRREL_API bool sq_can_suspend(HSQUIRRELVM v);
    00279 SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
    00280 SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
    00281 SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
    00282 SQUIRREL_API void sq_close(HSQUIRRELVM v);
    00283 SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
    00284 SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
    00285 SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
    00286 SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
    00287 SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
    00288 SQUIRREL_API bool sq_resumecatch(HSQUIRRELVM v, int suspend = -1);
    00289 SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror);
    00290 SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
    00291
    00292 /*compiler*/
    00293 SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
    00294 SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
    00295 SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
    00296 SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
    00297 SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
    00298
    00299 /*stack operations*/
    00300 SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
    00301 SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
    00302 SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
    00303 SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
    00304 SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
    00305 SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
    00306 SQUIRREL_API void sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
    00307 SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
    00308 SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
    00309
    00310 /*object creation handling*/
    00311 SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
    00312 SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
    00313 SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
    00314 SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
    00315 SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
    00316 SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
    00317 SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
    00318 SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
    00319 SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
    00320 SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
    00321 SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
    00322 SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
    00323 SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
    00324 SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
    00325 SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
    00326 SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
    00327 SQUIRREL_API void sq_tostring(HSQUIRRELVM v,SQInteger idx);
    00328 SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
    00329 SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
    00330 SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
    00331 SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
    00332 SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
    00333 SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
    00334 SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
    00335 SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
    00336 SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
    00337 SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
    00338 SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
    00339 SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
    00340 SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
    00341 SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
    00342 SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
    00343 SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
    00344 SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
    00345 SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
    00346 SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
    00347 SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
    00348 SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
    00349 SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
    00350 SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
    00351 SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
    00352
    00353 /*object manipulation*/
    00354 SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
    00355 SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
    00356 SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
    00357 SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
    00358 SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
    00359 SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
    00360 SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
    00361 SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
    00362 SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
    00363 SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
    00364 SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
    00365 SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
    00366 SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
    00367 SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
    00368 SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
    00369 SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
    00370 SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
    00371 SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
    00372 SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
    00373 SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
    00374 SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
    00375 SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
    00376 SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
    00377 SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
    00378 SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
    00379
    00380 /*calls*/
    00381 SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror, int suspend = -1);
    00382 SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
    00383 SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
    00384 SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
    00385 SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
    00386 SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
    00387 SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
    00388
    00389 /*raw object handling*/
    00390 SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
    00391 SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
    00392 SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
    00393 SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
    00394 SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
    00395 SQUIRREL_API const SQChar *sq_objtostring(HSQOBJECT *o);
    00396 SQUIRREL_API SQBool sq_objtobool(HSQOBJECT *o);
    00397 SQUIRREL_API SQInteger sq_objtointeger(HSQOBJECT *o);
    00398 SQUIRREL_API SQFloat sq_objtofloat(HSQOBJECT *o);
    00399 SQUIRREL_API SQRESULT sq_getobjtypetag(HSQOBJECT *o,SQUserPointer * typetag);
    00400
    00401 /*GC*/
    00402 SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
    00403
    00404 /*serialization*/
    00405 SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
    00406 SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
    00407
    00408 /*mem allocation*/
    00409 SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
    00410 SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
    00411 SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
    00412
    00413 /*debug*/
    00414 SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
    00415 SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
    00416
    00417 /*UTILITY MACRO*/
    00418 #define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
    00419 #define sq_istable(o) ((o)._type==OT_TABLE)
    00420 #define sq_isarray(o) ((o)._type==OT_ARRAY)
    00421 #define sq_isfunction(o) ((o)._type==OT_FUNCPROTO)
    00422 #define sq_isclosure(o) ((o)._type==OT_CLOSURE)
    00423 #define sq_isgenerator(o) ((o)._type==OT_GENERATOR)
    00424 #define sq_isnativeclosure(o) ((o)._type==OT_NATIVECLOSURE)
    00425 #define sq_isstring(o) ((o)._type==OT_STRING)
    00426 #define sq_isinteger(o) ((o)._type==OT_INTEGER)
    00427 #define sq_isfloat(o) ((o)._type==OT_FLOAT)
    00428 #define sq_isuserpointer(o) ((o)._type==OT_USERPOINTER)
    00429 #define sq_isuserdata(o) ((o)._type==OT_USERDATA)
    00430 #define sq_isthread(o) ((o)._type==OT_THREAD)
    00431 #define sq_isnull(o) ((o)._type==OT_NULL)
    00432 #define sq_isclass(o) ((o)._type==OT_CLASS)
    00433 #define sq_isinstance(o) ((o)._type==OT_INSTANCE)
    00434 #define sq_isbool(o) ((o)._type==OT_BOOL)
    00435 #define sq_isweakref(o) ((o)._type==OT_WEAKREF)
    00436 #define sq_type(o) ((o)._type)
    00437
    00438 /* deprecated */
    00439 #define sq_createslot(v,n) sq_newslot(v,n,SQFalse)
    00440
    00441 #define SQ_OK (0)
    00442 #define SQ_ERROR (-1)
    00443
    00444 #define SQ_FAILED(res) (res<0)
    00445 #define SQ_SUCCEEDED(res) (res>=0)
    00446
    00447 #ifdef __cplusplus
    00448 } /*extern "C"*/
    00449 #endif
    00450
    00451 #endif /*_SQUIRREL_H_*/