sqrat  0.9
sqrat
 All Classes Functions Variables Enumerations Enumerator Pages
sqmodule.h
1 //
2 // SqModule: API used to communicate with and register squirrel modules
3 //
4 
5 //
6 // Copyright (c) 2009 Brandon Jones
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
26 //
27 
28 #if !defined(_SQ_MODULE_H_)
29 #define _SQ_MODULE_H_
30 
31 #include "squirrel.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
42  typedef struct {
43  /*vm*/
44  HSQUIRRELVM (*open)(SQInteger initialstacksize);
45  HSQUIRRELVM (*newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
46  void (*seterrorhandler)(HSQUIRRELVM v);
47  void (*close)(HSQUIRRELVM v);
48  void (*setforeignptr)(HSQUIRRELVM v,SQUserPointer p);
49  SQUserPointer (*getforeignptr)(HSQUIRRELVM v);
50 #if SQUIRREL_VERSION_NUMBER >= 300
51  void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc, SQPRINTFUNCTION);
52 #else
53  void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
54 #endif
55  SQPRINTFUNCTION (*getprintfunc)(HSQUIRRELVM v);
56  SQRESULT (*suspendvm)(HSQUIRRELVM v);
57  SQRESULT (*wakeupvm)(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
58  SQInteger (*getvmstate)(HSQUIRRELVM v);
59 
60  /*compiler*/
61  SQRESULT (*compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
62  SQRESULT (*compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
63  void (*enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
64  void (*notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
65  void (*setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
66 
67  /*stack operations*/
68  void (*push)(HSQUIRRELVM v,SQInteger idx);
69  void (*pop)(HSQUIRRELVM v,SQInteger nelemstopop);
70  void (*poptop)(HSQUIRRELVM v);
71  void (*remove)(HSQUIRRELVM v,SQInteger idx);
72  SQInteger (*gettop)(HSQUIRRELVM v);
73  void (*settop)(HSQUIRRELVM v,SQInteger newtop);
74 #if SQUIRREL_VERSION_NUMBER >= 300
75  SQRESULT (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
76 #else
77  void (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
78 #endif
79  SQInteger (*cmp)(HSQUIRRELVM v);
80  void (*move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
81 
82  /*object creation handling*/
83  SQUserPointer (*newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
84  void (*newtable)(HSQUIRRELVM v);
85  void (*newarray)(HSQUIRRELVM v,SQInteger size);
86  void (*newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
87  SQRESULT (*setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
88  SQRESULT (*bindenv)(HSQUIRRELVM v,SQInteger idx);
89  void (*pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
90  void (*pushfloat)(HSQUIRRELVM v,SQFloat f);
91  void (*pushinteger)(HSQUIRRELVM v,SQInteger n);
92  void (*pushbool)(HSQUIRRELVM v,SQBool b);
93  void (*pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
94  void (*pushnull)(HSQUIRRELVM v);
95  SQObjectType (*gettype)(HSQUIRRELVM v,SQInteger idx);
96  SQInteger (*getsize)(HSQUIRRELVM v,SQInteger idx);
97  SQRESULT (*getbase)(HSQUIRRELVM v,SQInteger idx);
98  SQBool (*instanceof)(HSQUIRRELVM v);
99 #if SQUIRREL_VERSION_NUMBER >= 300
100  SQRESULT (*tostring)(HSQUIRRELVM v,SQInteger idx);
101 #else
102  void (*tostring)(HSQUIRRELVM v,SQInteger idx);
103 #endif
104  void (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
105  SQRESULT (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
106  SQRESULT (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
107  SQRESULT (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
108  SQRESULT (*getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
109  SQRESULT (*getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
110  SQRESULT (*getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
111  SQRESULT (*getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
112  SQRESULT (*settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
113  SQRESULT (*gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
114  void (*setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
115  SQChar* (*getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
116  SQRESULT (*getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
117  SQRESULT (*setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
118  SQRESULT (*setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
119  SQRESULT (*getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
120  SQRESULT (*setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
121  SQRESULT (*newclass)(HSQUIRRELVM v,SQBool hasbase);
122  SQRESULT (*createinstance)(HSQUIRRELVM v,SQInteger idx);
123  SQRESULT (*setattributes)(HSQUIRRELVM v,SQInteger idx);
124  SQRESULT (*getattributes)(HSQUIRRELVM v,SQInteger idx);
125  SQRESULT (*getclass)(HSQUIRRELVM v,SQInteger idx);
126  void (*weakref)(HSQUIRRELVM v,SQInteger idx);
127  SQRESULT (*getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);
128 
129  /*object manipulation*/
130  void (*pushroottable)(HSQUIRRELVM v);
131  void (*pushregistrytable)(HSQUIRRELVM v);
132  void (*pushconsttable)(HSQUIRRELVM v);
133  SQRESULT (*setroottable)(HSQUIRRELVM v);
134  SQRESULT (*setconsttable)(HSQUIRRELVM v);
135  SQRESULT (*newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
136  SQRESULT (*deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
137  SQRESULT (*set)(HSQUIRRELVM v,SQInteger idx);
138  SQRESULT (*get)(HSQUIRRELVM v,SQInteger idx);
139  SQRESULT (*rawget)(HSQUIRRELVM v,SQInteger idx);
140  SQRESULT (*rawset)(HSQUIRRELVM v,SQInteger idx);
141  SQRESULT (*rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
142  SQRESULT (*arrayappend)(HSQUIRRELVM v,SQInteger idx);
143  SQRESULT (*arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
144  SQRESULT (*arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
145  SQRESULT (*arrayreverse)(HSQUIRRELVM v,SQInteger idx);
146  SQRESULT (*arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
147  SQRESULT (*arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
148  SQRESULT (*setdelegate)(HSQUIRRELVM v,SQInteger idx);
149  SQRESULT (*getdelegate)(HSQUIRRELVM v,SQInteger idx);
150  SQRESULT (*clone)(HSQUIRRELVM v,SQInteger idx);
151  SQRESULT (*setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
152  SQRESULT (*next)(HSQUIRRELVM v,SQInteger idx);
153  SQRESULT (*getweakrefval)(HSQUIRRELVM v,SQInteger idx);
154  SQRESULT (*clear)(HSQUIRRELVM v,SQInteger idx);
155 
156  /*calls*/
157  SQRESULT (*call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
158  SQRESULT (*resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
159  const SQChar* (*getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
160  const SQChar* (*getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
161  SQRESULT (*throwerror)(HSQUIRRELVM v,const SQChar *err);
162  void (*reseterror)(HSQUIRRELVM v);
163  void (*getlasterror)(HSQUIRRELVM v);
164 
165  /*raw object handling*/
166  SQRESULT (*getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
167  void (*pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
168  void (*addref)(HSQUIRRELVM v,HSQOBJECT *po);
169  SQBool (*release)(HSQUIRRELVM v,HSQOBJECT *po);
170  void (*resetobject)(HSQOBJECT *po);
171  const SQChar* (*objtostring)(const HSQOBJECT *o);
172  SQBool (*objtobool)(const HSQOBJECT *o);
173  SQInteger (*objtointeger)(const HSQOBJECT *o);
174  SQFloat (*objtofloat)(const HSQOBJECT *o);
175  SQRESULT (*getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);
176 
177  /*GC*/
178  SQInteger (*collectgarbage)(HSQUIRRELVM v);
179 
180  /*serialization*/
181  SQRESULT (*writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
182  SQRESULT (*readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
183 
184  /*mem allocation*/
185  void* (*malloc)(SQUnsignedInteger size);
186  void* (*realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
187  void (*free)(void *p,SQUnsignedInteger size);
188 
189  /*debug*/
190  SQRESULT (*stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
191  void (*setdebughook)(HSQUIRRELVM v);
192  } sq_api;
193  typedef sq_api* HSQAPI;
195 
196 #ifdef __cplusplus
197 } /*extern "C"*/
198 #endif
199 
200 #endif /*_SQ_MODULE_H_*/