sqmodule.h 11 KB

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