Team Fortress 2 Source Code as on 22/4/2020
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.

317 lines
9.1 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * pike.swg
  6. *
  7. * Pike configuration module.
  8. * ----------------------------------------------------------------------------- */
  9. %insert(runtime) "swigrun.swg"; // Common C API type-checking code
  10. %insert(runtime) "pikerun.swg"; // Pike run-time code
  11. %insert(runtime) %{
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <global.h>
  16. #include <module.h>
  17. #include <interpret.h>
  18. #ifdef __cplusplus
  19. }
  20. #endif
  21. %}
  22. /* -----------------------------------------------------------------------------
  23. * standard typemaps
  24. * ----------------------------------------------------------------------------- */
  25. /* --- Input arguments --- */
  26. /* Primitive datatypes. */
  27. %typemap(in, pikedesc="tInt")
  28. int, unsigned int, short, unsigned short,
  29. long, unsigned long, char, signed char, unsigned char,
  30. bool, enum SWIGTYPE, long long, unsigned long long
  31. {
  32. if ($input.type != T_INT)
  33. Pike_error("Bad argument: Expected an integer.\n");
  34. $1 = ($1_ltype) $input.u.integer;
  35. }
  36. %typemap(in, pikedesc="tFloat") float, double {
  37. if ($input.type != T_FLOAT)
  38. Pike_error("Bad argument: Expected a float.\n");
  39. $1 = ($1_ltype) $input.u.float_number;
  40. }
  41. %typemap(in, pikedesc="tStr") char *, char [ANY] {
  42. if ($input.type != T_STRING)
  43. Pike_error("Bad argument: Expected a string.\n");
  44. $1 = ($1_ltype) STR0($input.u.string);
  45. }
  46. /* Pointers, references and arrays */
  47. %typemap(in) SWIGTYPE *,
  48. SWIGTYPE &,
  49. SWIGTYPE []
  50. "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);"
  51. /* Void pointer. Accepts any kind of pointer */
  52. %typemap(in) void * "/* FIXME */";
  53. /* Object passed by value. Convert to a pointer */
  54. %typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */";
  55. /* Pointer to a class member */
  56. %typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */";
  57. /* Const primitive references. Passed by value */
  58. %typemap(in, pikedesc="tInt") const int & (int temp),
  59. const short & (short temp),
  60. const long & (long temp),
  61. const unsigned int & (unsigned int temp),
  62. const unsigned short & (unsigned short temp),
  63. const unsigned long & (unsigned long temp),
  64. const char & (char temp),
  65. const signed char & (signed char temp),
  66. const unsigned char & (unsigned char temp),
  67. const bool & (bool temp),
  68. const long long & ($*1_ltype temp),
  69. const unsigned long long & ($*1_ltype temp),
  70. const enum SWIGTYPE & ($*1_ltype temp)
  71. {
  72. if ($input.type != T_INT)
  73. Pike_error("Bad argument: Expected an integer.\n");
  74. temp = ($*1_ltype) $input.u.integer;
  75. $1 = &temp;
  76. }
  77. %typemap(in, pikedesc="tFloat") const float & (float temp),
  78. const double & (double temp)
  79. {
  80. if ($input.type != T_FLOAT)
  81. Pike_error("Bad argument: Expected a float.\n");
  82. temp = ($*1_ltype) $input.u.float_number;
  83. $1 = &temp;
  84. }
  85. /* -----------------------------------------------------------------------------
  86. * Output Typemaps
  87. * ----------------------------------------------------------------------------- */
  88. %typemap(out, pikedesc="tInt")
  89. int, unsigned int,
  90. short, unsigned short,
  91. long, unsigned long,
  92. char, signed char, unsigned char,
  93. bool, enum SWIGTYPE
  94. "push_int($1);";
  95. %typemap(out, pikedesc="tInt") long long "push_int64($1);";
  96. %typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);";
  97. %typemap(out, pikedesc="tFloat") float, double "push_float($1);";
  98. %typemap(out, pikedesc="tStr") char * "push_text($1);";
  99. /* Pointers, references, and arrays */
  100. %typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
  101. /* Void return value; don't push anything */
  102. %typemap(out, pikedesc="tVoid") void "";
  103. /* Dynamic casts */
  104. %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */";
  105. /* Member pointer */
  106. %typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */";
  107. /* Special typemap for character array return values */
  108. %typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);";
  109. /* Primitive types--return by value */
  110. %typemap(out, pikedesc="tObj") SWIGTYPE
  111. #ifdef __cplusplus
  112. {
  113. $&1_ltype resultptr;
  114. resultptr = new $1_ltype(($1_ltype &) $1);
  115. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  116. }
  117. #else
  118. {
  119. $&1_ltype resultptr;
  120. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  121. memmove(resultptr, &$1, sizeof($1_type));
  122. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  123. }
  124. #endif
  125. /* References to primitive types. Return by value */
  126. %typemap(out, pikedesc="tInt") const int &, const unsigned int &,
  127. const short &, const unsigned short &,
  128. const long &, const unsigned long &,
  129. const char &, const signed char &, const unsigned char &,
  130. const bool &,
  131. const long long &, const unsigned long long &,
  132. const enum SWIGTYPE & ($*1_ltype temp)
  133. "push_int(*($1));";
  134. %typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));";
  135. /************************ Constant Typemaps *****************************/
  136. %typemap(constant)
  137. int, unsigned int,
  138. short, unsigned short,
  139. long, unsigned long,
  140. signed char, unsigned char,
  141. bool, enum SWIGTYPE,
  142. long long, unsigned long long
  143. "add_integer_constant(\"$symname\", $1, 0);";
  144. %typemap(constant) char
  145. "add_integer_constant(\"$symname\", '$1', 0);";
  146. %typemap(constant) long long, unsigned long long
  147. "add_integer_constant(\"$symname\", $1, 0);";
  148. %typemap(constant) float, double
  149. "add_float_constant(\"$symname\", $1, 0);";
  150. %typemap(constant) char *
  151. "add_string_constant(\"$symname\", \"$1\", 0);";
  152. /* ------------------------------------------------------------
  153. * String & length
  154. * ------------------------------------------------------------ */
  155. %typemap(in, pikedesc="tStr") (char *STRING, int LENGTH) {
  156. if ($input.type != T_STRING)
  157. Pike_error("Bad argument: Expected a string.\n");
  158. $1 = ($1_ltype) STR0($input.u.string);
  159. $2 = ($2_ltype) $input.u.string->length;
  160. }
  161. /* ------------------------------------------------------------
  162. * ANSI C typemaps
  163. * ------------------------------------------------------------ */
  164. %typemap(in, pikedesc="tInt") size_t {
  165. if ($input.type != T_INT)
  166. Pike_error("Bad argument: Expected an integer.\n");
  167. $1 = ($1_ltype) $input.u.integer;
  168. }
  169. %typemap(out) size_t = long;
  170. /* ------------------------------------------------------------
  171. * Typechecking rules
  172. * ------------------------------------------------------------ */
  173. %typecheck(SWIG_TYPECHECK_INTEGER)
  174. int, short, long,
  175. unsigned int, unsigned short, unsigned long,
  176. signed char, unsigned char,
  177. long long, unsigned long long,
  178. const int &, const short &, const long &,
  179. const unsigned int &, const unsigned short &, const unsigned long &,
  180. const long long &, const unsigned long long &,
  181. enum SWIGTYPE, enum SWIGTYPE &,
  182. bool, const bool &
  183. {
  184. $1 = ($input.type == T_INT) ? 1 : 0;
  185. }
  186. %typecheck(SWIG_TYPECHECK_DOUBLE)
  187. float, double,
  188. const float &, const double &
  189. {
  190. $1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0;
  191. }
  192. %typecheck(SWIG_TYPECHECK_CHAR) char {
  193. $1 = ($input.type == T_INT) ? 1 : 0;
  194. }
  195. %typecheck(SWIG_TYPECHECK_STRING) char * {
  196. $1 = ($input.type == T_STRING) ? 1 : 0;
  197. }
  198. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
  199. void *ptr;
  200. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) {
  201. $1 = 0;
  202. } else {
  203. $1 = 1;
  204. }
  205. }
  206. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
  207. void *ptr;
  208. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) {
  209. $1 = 0;
  210. } else {
  211. $1 = 1;
  212. }
  213. }
  214. %typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
  215. void *ptr;
  216. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) {
  217. $1 = 0;
  218. } else {
  219. $1 = 1;
  220. }
  221. }
  222. /* ------------------------------------------------------------
  223. * Overloaded operator support
  224. * ------------------------------------------------------------ */
  225. #ifdef __cplusplus
  226. %rename("`+") *::operator+;
  227. %rename("`-") *::operator-;
  228. %rename("`*") *::operator*;
  229. %rename("`/") *::operator/;
  230. %rename("`%") *::operator%;
  231. %rename("`<<") *::operator<<;
  232. %rename("`>>") *::operator>>;
  233. %rename("`&") *::operator&;
  234. %rename("`|") *::operator|;
  235. %rename("`^") *::operator^;
  236. %rename("`~") *::operator~;
  237. %rename("`<") *::operator<;
  238. %rename("`>") *::operator>;
  239. %rename("`==") *::operator==;
  240. /* Special cases */
  241. %rename("`()") *::operator();
  242. #endif
  243. /* ------------------------------------------------------------
  244. * The start of the Pike initialization function
  245. * ------------------------------------------------------------ */
  246. %init "swiginit.swg"
  247. %init %{
  248. #ifdef __cplusplus
  249. extern "C"
  250. #endif
  251. PIKE_MODULE_EXIT {}
  252. #ifdef __cplusplus
  253. extern "C"
  254. #endif
  255. PIKE_MODULE_INIT
  256. {
  257. struct program *pr;
  258. SWIG_InitializeModule(0);
  259. %}
  260. /* pike keywords */
  261. %include <pikekw.swg>