sqmodule.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. /// @cond DEV
  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,SQBool raiseerror);
  56. SQRESULT (*compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
  57. void (*enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
  58. void (*notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
  59. void (*setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
  60. /*stack operations*/
  61. void (*push)(HSQUIRRELVM v,SQInteger idx);
  62. void (*pop)(HSQUIRRELVM v,SQInteger nelemstopop);
  63. void (*poptop)(HSQUIRRELVM v);
  64. void (*remove)(HSQUIRRELVM v,SQInteger idx);
  65. SQInteger (*gettop)(HSQUIRRELVM v);
  66. void (*settop)(HSQUIRRELVM v,SQInteger newtop);
  67. #if SQUIRREL_VERSION_NUMBER >= 300
  68. SQRESULT (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
  69. #else
  70. void (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
  71. #endif
  72. SQInteger (*cmp)(HSQUIRRELVM v);
  73. void (*move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
  74. /*object creation handling*/
  75. SQUserPointer (*newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
  76. void (*newtable)(HSQUIRRELVM v);
  77. void (*newarray)(HSQUIRRELVM v,SQInteger size);
  78. void (*newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
  79. SQRESULT (*setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
  80. SQRESULT (*bindenv)(HSQUIRRELVM v,SQInteger idx);
  81. void (*pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
  82. void (*pushfloat)(HSQUIRRELVM v,SQFloat f);
  83. void (*pushinteger)(HSQUIRRELVM v,SQInteger n);
  84. void (*pushbool)(HSQUIRRELVM v,SQBool b);
  85. void (*pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
  86. void (*pushnull)(HSQUIRRELVM v);
  87. SQObjectType (*gettype)(HSQUIRRELVM v,SQInteger idx);
  88. SQInteger (*getsize)(HSQUIRRELVM v,SQInteger idx);
  89. SQRESULT (*getbase)(HSQUIRRELVM v,SQInteger idx);
  90. SQBool (*instanceof)(HSQUIRRELVM v);
  91. #if SQUIRREL_VERSION_NUMBER >= 300
  92. SQRESULT (*tostring)(HSQUIRRELVM v,SQInteger idx);
  93. #else
  94. void (*tostring)(HSQUIRRELVM v,SQInteger idx);
  95. #endif
  96. void (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
  97. SQRESULT (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
  98. SQRESULT (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
  99. SQRESULT (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
  100. SQRESULT (*getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
  101. SQRESULT (*getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
  102. SQRESULT (*getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
  103. SQRESULT (*getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
  104. SQRESULT (*settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
  105. SQRESULT (*gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
  106. void (*setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
  107. SQChar* (*getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
  108. SQRESULT (*getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
  109. SQRESULT (*setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
  110. SQRESULT (*setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
  111. SQRESULT (*getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
  112. SQRESULT (*setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
  113. SQRESULT (*newclass)(HSQUIRRELVM v,SQBool hasbase);
  114. SQRESULT (*createinstance)(HSQUIRRELVM v,SQInteger idx);
  115. SQRESULT (*setattributes)(HSQUIRRELVM v,SQInteger idx);
  116. SQRESULT (*getattributes)(HSQUIRRELVM v,SQInteger idx);
  117. SQRESULT (*getclass)(HSQUIRRELVM v,SQInteger idx);
  118. void (*weakref)(HSQUIRRELVM v,SQInteger idx);
  119. SQRESULT (*getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);
  120. /*object manipulation*/
  121. void (*pushroottable)(HSQUIRRELVM v);
  122. void (*pushregistrytable)(HSQUIRRELVM v);
  123. void (*pushconsttable)(HSQUIRRELVM v);
  124. SQRESULT (*setroottable)(HSQUIRRELVM v);
  125. SQRESULT (*setconsttable)(HSQUIRRELVM v);
  126. SQRESULT (*newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
  127. SQRESULT (*deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  128. SQRESULT (*set)(HSQUIRRELVM v,SQInteger idx);
  129. SQRESULT (*get)(HSQUIRRELVM v,SQInteger idx);
  130. SQRESULT (*rawget)(HSQUIRRELVM v,SQInteger idx);
  131. SQRESULT (*rawset)(HSQUIRRELVM v,SQInteger idx);
  132. SQRESULT (*rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  133. SQRESULT (*arrayappend)(HSQUIRRELVM v,SQInteger idx);
  134. SQRESULT (*arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
  135. SQRESULT (*arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
  136. SQRESULT (*arrayreverse)(HSQUIRRELVM v,SQInteger idx);
  137. SQRESULT (*arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
  138. SQRESULT (*arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
  139. SQRESULT (*setdelegate)(HSQUIRRELVM v,SQInteger idx);
  140. SQRESULT (*getdelegate)(HSQUIRRELVM v,SQInteger idx);
  141. SQRESULT (*clone)(HSQUIRRELVM v,SQInteger idx);
  142. SQRESULT (*setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
  143. SQRESULT (*next)(HSQUIRRELVM v,SQInteger idx);
  144. SQRESULT (*getweakrefval)(HSQUIRRELVM v,SQInteger idx);
  145. SQRESULT (*clear)(HSQUIRRELVM v,SQInteger idx);
  146. /*calls*/
  147. SQRESULT (*call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
  148. SQRESULT (*resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
  149. const SQChar* (*getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
  150. const SQChar* (*getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
  151. SQRESULT (*throwerror)(HSQUIRRELVM v,const SQChar *err);
  152. void (*reseterror)(HSQUIRRELVM v);
  153. void (*getlasterror)(HSQUIRRELVM v);
  154. /*raw object handling*/
  155. SQRESULT (*getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
  156. void (*pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
  157. void (*addref)(HSQUIRRELVM v,HSQOBJECT *po);
  158. SQBool (*release)(HSQUIRRELVM v,HSQOBJECT *po);
  159. void (*resetobject)(HSQOBJECT *po);
  160. const SQChar* (*objtostring)(const HSQOBJECT *o);
  161. SQBool (*objtobool)(const HSQOBJECT *o);
  162. SQInteger (*objtointeger)(const HSQOBJECT *o);
  163. SQFloat (*objtofloat)(const HSQOBJECT *o);
  164. SQRESULT (*getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);
  165. /*GC*/
  166. SQInteger (*collectgarbage)(HSQUIRRELVM v);
  167. /*serialization*/
  168. SQRESULT (*writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
  169. SQRESULT (*readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
  170. /*mem allocation*/
  171. void* (*malloc)(SQUnsignedInteger size);
  172. void* (*realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
  173. void (*free)(void *p,SQUnsignedInteger size);
  174. /*debug*/
  175. SQRESULT (*stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
  176. void (*setdebughook)(HSQUIRRELVM v);
  177. } sq_api;
  178. typedef sq_api* HSQAPI;
  179. /// @endcond
  180. #ifdef __cplusplus
  181. } /*extern "C"*/
  182. #endif
  183. #endif /*_SQ_MODULE_H_*/