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.

334 lines
12 KiB

  1. // SqPlusConst.h
  2. // SqPlus constant type and constant member function support created by Simon Michelmore.
  3. // Modular integration 11/14/05 jcs.
  4. #ifdef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
  5. #undef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
  6. // Kamaitati's NULL_INSTANCE support. 5/28/06 jcs
  7. #ifdef SQPLUS_SUPPORT_NULL_INSTANCES
  8. #define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
  9. DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
  10. namespace SqPlus { \
  11. inline void Push(HSQUIRRELVM v,const TYPE * value) { \
  12. if (!value) sq_pushnull(v); \
  13. else if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) \
  14. throw SquirrelError(_T("Push(): could not create INSTANCE (check registration name)")); } \
  15. inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(GetTypeName(value),value)) throw SquirrelError(_T("Push(): could not create INSTANCE copy (check registration name)")); } \
  16. inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
  17. inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
  18. } // nameSpace SqPlus
  19. #else
  20. #define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
  21. DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
  22. namespace SqPlus { \
  23. inline void Push(HSQUIRRELVM v,const TYPE * value) { if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) throw SquirrelError(_T("Push(): could not create INSTANCE (check registration name)")); } \
  24. inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(GetTypeName(value),value)) throw SquirrelError(_T("Push(): could not create INSTANCE copy (check registration name)")); } \
  25. inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
  26. inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
  27. } // nameSpace SqPlus
  28. #endif
  29. #define DECLARE_INSTANCE_TYPE(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,TYPE)
  30. #define DECLARE_INSTANCE_TYPE_NAME(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME)
  31. #endif
  32. #ifdef SQPLUS_CALL_CONST_MFUNC_RET0
  33. #undef SQPLUS_CALL_CONST_MFUNC_RET0
  34. template <typename Callee>
  35. static int Call(Callee & callee,RT (Callee::*func)() const,HSQUIRRELVM v,int /*index*/) {
  36. RT ret = (callee.*func)();
  37. Push(v,ret);
  38. return 1;
  39. }
  40. template <typename Callee,typename P1>
  41. static int Call(Callee & callee,RT (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
  42. sq_argassert(1,index + 0);
  43. RT ret = (callee.*func)(
  44. Get(TypeWrapper<P1>(),v,index + 0)
  45. );
  46. Push(v,ret);
  47. return 1;
  48. }
  49. template<typename Callee,typename P1,typename P2>
  50. static int Call(Callee & callee,RT (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
  51. sq_argassert(1,index + 0);
  52. sq_argassert(2,index + 1);
  53. RT ret = (callee.*func)(
  54. Get(TypeWrapper<P1>(),v,index + 0),
  55. Get(TypeWrapper<P2>(),v,index + 1)
  56. );
  57. Push(v,ret);
  58. return 1;
  59. }
  60. template<typename Callee,typename P1,typename P2,typename P3>
  61. static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
  62. sq_argassert(1,index + 0);
  63. sq_argassert(2,index + 1);
  64. sq_argassert(3,index + 2);
  65. RT ret = (callee.*func)(
  66. Get(TypeWrapper<P1>(),v,index + 0),
  67. Get(TypeWrapper<P2>(),v,index + 1),
  68. Get(TypeWrapper<P3>(),v,index + 2)
  69. );
  70. Push(v,ret);
  71. return 1;
  72. }
  73. template<typename Callee,typename P1,typename P2,typename P3,typename P4>
  74. static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
  75. sq_argassert(1,index + 0);
  76. sq_argassert(2,index + 1);
  77. sq_argassert(3,index + 2);
  78. sq_argassert(4,index + 3);
  79. RT ret = (callee.*func)(
  80. Get(TypeWrapper<P1>(),v,index + 0),
  81. Get(TypeWrapper<P2>(),v,index + 1),
  82. Get(TypeWrapper<P3>(),v,index + 2),
  83. Get(TypeWrapper<P4>(),v,index + 3)
  84. );
  85. Push(v,ret);
  86. return 1;
  87. }
  88. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
  89. static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
  90. sq_argassert(1,index + 0);
  91. sq_argassert(2,index + 1);
  92. sq_argassert(3,index + 2);
  93. sq_argassert(4,index + 3);
  94. sq_argassert(5,index + 4);
  95. RT ret = (callee.*func)(
  96. Get(TypeWrapper<P1>(),v,index + 0),
  97. Get(TypeWrapper<P2>(),v,index + 1),
  98. Get(TypeWrapper<P3>(),v,index + 2),
  99. Get(TypeWrapper<P4>(),v,index + 3),
  100. Get(TypeWrapper<P5>(),v,index + 4)
  101. );
  102. Push(v,ret);
  103. return 1;
  104. }
  105. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
  106. static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
  107. sq_argassert(1,index + 0);
  108. sq_argassert(2,index + 1);
  109. sq_argassert(3,index + 2);
  110. sq_argassert(4,index + 3);
  111. sq_argassert(5,index + 4);
  112. sq_argassert(6,index + 5);
  113. RT ret = (callee.*func)(
  114. Get(TypeWrapper<P1>(),v,index + 0),
  115. Get(TypeWrapper<P2>(),v,index + 1),
  116. Get(TypeWrapper<P3>(),v,index + 2),
  117. Get(TypeWrapper<P4>(),v,index + 3),
  118. Get(TypeWrapper<P5>(),v,index + 4),
  119. Get(TypeWrapper<P6>(),v,index + 5)
  120. );
  121. Push(v,ret);
  122. return 1;
  123. }
  124. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
  125. static int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
  126. sq_argassert(1,index + 0);
  127. sq_argassert(2,index + 1);
  128. sq_argassert(3,index + 2);
  129. sq_argassert(4,index + 3);
  130. sq_argassert(5,index + 4);
  131. sq_argassert(6,index + 5);
  132. sq_argassert(7,index + 6);
  133. RT ret = (callee.*func)(
  134. Get(TypeWrapper<P1>(),v,index + 0),
  135. Get(TypeWrapper<P2>(),v,index + 1),
  136. Get(TypeWrapper<P3>(),v,index + 2),
  137. Get(TypeWrapper<P4>(),v,index + 3),
  138. Get(TypeWrapper<P5>(),v,index + 4),
  139. Get(TypeWrapper<P6>(),v,index + 5),
  140. Get(TypeWrapper<P7>(),v,index + 6)
  141. );
  142. Push(v,ret);
  143. return 1;
  144. }
  145. #endif
  146. #ifdef SQPLUS_CALL_CONST_MFUNC_NORET
  147. #undef SQPLUS_CALL_CONST_MFUNC_NORET
  148. template<typename Callee>
  149. static int Call(Callee & callee,void (Callee::*func)() const,HSQUIRRELVM,int /*index*/) {
  150. (callee.*func)();
  151. return 0;
  152. }
  153. template<typename Callee,typename P1>
  154. static int Call(Callee & callee,void (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
  155. sq_argassert(1,index + 0);
  156. (callee.*func)(
  157. Get(TypeWrapper<P1>(),v,index + 0)
  158. );
  159. return 0;
  160. }
  161. template<typename Callee,typename P1,typename P2>
  162. static int Call(Callee & callee,void (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
  163. sq_argassert(1,index + 0);
  164. sq_argassert(2,index + 1);
  165. (callee.*func)(
  166. Get(TypeWrapper<P1>(),v,index + 0),
  167. Get(TypeWrapper<P2>(),v,index + 1)
  168. );
  169. return 0;
  170. }
  171. template<typename Callee,typename P1,typename P2,typename P3>
  172. static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
  173. sq_argassert(1,index + 0);
  174. sq_argassert(2,index + 1);
  175. sq_argassert(3,index + 2);
  176. (callee.*func)(
  177. Get(TypeWrapper<P1>(),v,index + 0),
  178. Get(TypeWrapper<P2>(),v,index + 1),
  179. Get(TypeWrapper<P3>(),v,index + 2)
  180. );
  181. return 0;
  182. }
  183. template<typename Callee,typename P1,typename P2,typename P3,typename P4>
  184. static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
  185. sq_argassert(1,index + 0);
  186. sq_argassert(2,index + 1);
  187. sq_argassert(3,index + 2);
  188. sq_argassert(4,index + 3);
  189. (callee.*func)(
  190. Get(TypeWrapper<P1>(),v,index + 0),
  191. Get(TypeWrapper<P2>(),v,index + 1),
  192. Get(TypeWrapper<P3>(),v,index + 2),
  193. Get(TypeWrapper<P4>(),v,index + 3)
  194. );
  195. return 0;
  196. }
  197. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
  198. static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
  199. sq_argassert(1,index + 0);
  200. sq_argassert(2,index + 1);
  201. sq_argassert(3,index + 2);
  202. sq_argassert(4,index + 3);
  203. sq_argassert(5,index + 4);
  204. (callee.*func)(
  205. Get(TypeWrapper<P1>(),v,index + 0),
  206. Get(TypeWrapper<P2>(),v,index + 1),
  207. Get(TypeWrapper<P3>(),v,index + 2),
  208. Get(TypeWrapper<P4>(),v,index + 3),
  209. Get(TypeWrapper<P5>(),v,index + 4)
  210. );
  211. return 0;
  212. }
  213. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
  214. static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
  215. sq_argassert(1,index + 0);
  216. sq_argassert(2,index + 1);
  217. sq_argassert(3,index + 2);
  218. sq_argassert(4,index + 3);
  219. sq_argassert(5,index + 4);
  220. sq_argassert(6,index + 5);
  221. (callee.*func)(
  222. Get(TypeWrapper<P1>(),v,index + 0),
  223. Get(TypeWrapper<P2>(),v,index + 1),
  224. Get(TypeWrapper<P3>(),v,index + 2),
  225. Get(TypeWrapper<P4>(),v,index + 3),
  226. Get(TypeWrapper<P5>(),v,index + 4),
  227. Get(TypeWrapper<P6>(),v,index + 5)
  228. );
  229. return 0;
  230. }
  231. template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
  232. static int Call(Callee & callee,void (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
  233. sq_argassert(1,index + 0);
  234. sq_argassert(2,index + 1);
  235. sq_argassert(3,index + 2);
  236. sq_argassert(4,index + 3);
  237. sq_argassert(5,index + 4);
  238. sq_argassert(6,index + 5);
  239. sq_argassert(7,index + 6);
  240. (callee.*func)(
  241. Get(TypeWrapper<P1>(),v,index + 0),
  242. Get(TypeWrapper<P2>(),v,index + 1),
  243. Get(TypeWrapper<P3>(),v,index + 2),
  244. Get(TypeWrapper<P4>(),v,index + 3),
  245. Get(TypeWrapper<P5>(),v,index + 4),
  246. Get(TypeWrapper<P6>(),v,index + 5),
  247. Get(TypeWrapper<P7>(),v,index + 6)
  248. );
  249. return 0;
  250. }
  251. #endif
  252. #ifdef SQPLUS_CALL_CONST_MFUNC_RET1
  253. #undef SQPLUS_CALL_CONST_MFUNC_RET1
  254. template<typename Callee,typename RT>
  255. int Call(Callee & callee, RT (Callee::*func)() const,HSQUIRRELVM v,int index) {
  256. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  257. }
  258. template<typename Callee,typename RT,typename P1>
  259. int Call(Callee & callee,RT (Callee::*func)(P1) const,HSQUIRRELVM v,int index) {
  260. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  261. }
  262. template<typename Callee,typename RT,typename P1,typename P2>
  263. int Call(Callee & callee,RT (Callee::*func)(P1,P2) const,HSQUIRRELVM v,int index) {
  264. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  265. }
  266. template<typename Callee,typename RT,typename P1,typename P2,typename P3>
  267. int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3) const,HSQUIRRELVM v,int index) {
  268. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  269. }
  270. template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4>
  271. int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4) const,HSQUIRRELVM v,int index) {
  272. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  273. }
  274. template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5>
  275. int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5) const,HSQUIRRELVM v,int index) {
  276. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  277. }
  278. template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
  279. int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6) const,HSQUIRRELVM v,int index) {
  280. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  281. }
  282. template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
  283. int Call(Callee & callee,RT (Callee::*func)(P1,P2,P3,P4,P5,P6,P7) const,HSQUIRRELVM v,int index) {
  284. return ReturnSpecialization<RT>::Call(callee,func,v,index);
  285. }
  286. #undef SQPLUS_CALL_CONST_MFUNC_RET1
  287. #endif
  288. #ifdef SQ_REG_CONST_STATIC_VAR
  289. #undef SQ_REG_CONST_STATIC_VAR
  290. template<typename VarType>
  291. SQClassDefBase & staticVar(const VarType * pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_ONLY) {
  292. struct CV {
  293. const VarType * var;
  294. } cv; // Cast Variable helper.
  295. cv.var = pvar;
  296. RegisterInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,VarAccessType(access|VAR_ACCESS_STATIC));
  297. return *this;
  298. } // staticVar
  299. #endif
  300. // SqPlusConst.h