pike.swg 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* -----------------------------------------------------------------------------
  2. * pike.swg
  3. *
  4. * Pike configuration module.
  5. * ----------------------------------------------------------------------------- */
  6. %insert(runtime) "swigrun.swg"; // Common C API type-checking code
  7. %insert(runtime) "pikerun.swg"; // Pike run-time code
  8. %insert(runtime) %{
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <pike/global.h>
  13. #include <pike/module.h>
  14. #include <pike/interpret.h>
  15. #ifdef __cplusplus
  16. }
  17. #endif
  18. %}
  19. /* -----------------------------------------------------------------------------
  20. * standard typemaps
  21. * ----------------------------------------------------------------------------- */
  22. /* --- Input arguments --- */
  23. /* Primitive datatypes. */
  24. %typemap(in, pikedesc="tInt")
  25. int, unsigned int, short, unsigned short,
  26. long, unsigned long, char, signed char, unsigned char,
  27. bool, enum SWIGTYPE, long long, unsigned long long
  28. {
  29. if ($input.type != T_INT)
  30. Pike_error("Bad argument: Expected an integer.\n");
  31. $1 = ($1_ltype) $input.u.integer;
  32. }
  33. %typemap(in, pikedesc="tFloat") float, double {
  34. if ($input.type != T_FLOAT)
  35. Pike_error("Bad argument: Expected a float.\n");
  36. $1 = ($1_ltype) $input.u.float_number;
  37. }
  38. %typemap(in, pikedesc="tStr") char *, char [ANY] {
  39. if ($input.type != T_STRING)
  40. Pike_error("Bad argument: Expected a string.\n");
  41. $1 = ($1_ltype) STR0($input.u.string);
  42. }
  43. /* Pointers, references and arrays */
  44. %typemap(in) SWIGTYPE *,
  45. SWIGTYPE &,
  46. SWIGTYPE &&,
  47. SWIGTYPE []
  48. "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);"
  49. /* Void pointer. Accepts any kind of pointer */
  50. %typemap(in) void * "/* FIXME */";
  51. /* Object passed by value. Convert to a pointer */
  52. %typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */";
  53. /* Pointer to a class member */
  54. %typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */";
  55. /* Const primitive references. Passed by value */
  56. %typemap(in, pikedesc="tInt") const int & (int temp),
  57. const short & (short temp),
  58. const long & (long temp),
  59. const unsigned int & (unsigned int temp),
  60. const unsigned short & (unsigned short temp),
  61. const unsigned long & (unsigned long temp),
  62. const char & (char temp),
  63. const signed char & (signed char temp),
  64. const unsigned char & (unsigned char temp),
  65. const bool & (bool temp),
  66. const long long & ($*1_ltype temp),
  67. const unsigned long long & ($*1_ltype temp),
  68. const enum SWIGTYPE & ($*1_ltype temp),
  69. const enum SWIGTYPE && ($*1_ltype temp)
  70. {
  71. if ($input.type != T_INT)
  72. Pike_error("Bad argument: Expected an integer.\n");
  73. temp = ($*1_ltype) $input.u.integer;
  74. $1 = &temp;
  75. }
  76. %typemap(in, pikedesc="tFloat") const float & (float temp),
  77. const double & (double temp)
  78. {
  79. if ($input.type != T_FLOAT)
  80. Pike_error("Bad argument: Expected a float.\n");
  81. temp = ($*1_ltype) $input.u.float_number;
  82. $1 = &temp;
  83. }
  84. /* -----------------------------------------------------------------------------
  85. * Output Typemaps
  86. * ----------------------------------------------------------------------------- */
  87. %typemap(out, pikedesc="tInt")
  88. int, unsigned int,
  89. short, unsigned short,
  90. long, unsigned long,
  91. char, signed char, unsigned char,
  92. bool, enum SWIGTYPE
  93. "push_int($1);";
  94. %typemap(out, pikedesc="tInt") long long "push_int64($1);";
  95. %typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);";
  96. %typemap(out, pikedesc="tFloat") float, double "push_float($1);";
  97. %typemap(out, pikedesc="tStr") char * "push_text($1);";
  98. /* Pointers, references, and arrays */
  99. %typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
  100. /* Void return value; don't push anything */
  101. %typemap(out, pikedesc="tVoid") void "";
  102. /* Dynamic casts */
  103. %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */";
  104. /* Member pointer */
  105. %typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */";
  106. /* Special typemap for character array return values */
  107. %typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);";
  108. /* Primitive types--return by value */
  109. %typemap(out, pikedesc="tObj") SWIGTYPE
  110. #ifdef __cplusplus
  111. {
  112. $&1_ltype resultptr;
  113. resultptr = new $1_ltype((const $1_ltype &) $1);
  114. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  115. }
  116. #else
  117. {
  118. $&1_ltype resultptr;
  119. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  120. memmove(resultptr, &$1, sizeof($1_type));
  121. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  122. }
  123. #endif
  124. /* References to primitive types. Return by value */
  125. %typemap(out, pikedesc="tInt") const int &, const unsigned int &,
  126. const short &, const unsigned short &,
  127. const long &, const unsigned long &,
  128. const char &, const signed char &, const unsigned char &,
  129. const bool &,
  130. const long long &, const unsigned long long &,
  131. const enum SWIGTYPE & ($*1_ltype temp),
  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) (char *STRING, int LENGTH), (char *STRING, size_t 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 &, 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 &&, 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. /* Array reference typemaps */
  223. %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
  224. %apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
  225. /* const pointers */
  226. %apply SWIGTYPE * { SWIGTYPE *const }
  227. /* ------------------------------------------------------------
  228. * Overloaded operator support
  229. * ------------------------------------------------------------ */
  230. #ifdef __cplusplus
  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. %rename("`^") *::operator^;
  241. %rename("`~") *::operator~;
  242. %rename("`<") *::operator<;
  243. %rename("`>") *::operator>;
  244. %rename("`==") *::operator==;
  245. /* Special cases */
  246. %rename("`()") *::operator();
  247. #endif
  248. /* ------------------------------------------------------------
  249. * The start of the Pike initialization function
  250. * ------------------------------------------------------------ */
  251. %init "swiginit.swg"
  252. %init %{
  253. #ifdef __cplusplus
  254. extern "C"
  255. #endif
  256. PIKE_MODULE_EXIT {}
  257. #ifdef __cplusplus
  258. extern "C"
  259. #endif
  260. PIKE_MODULE_INIT
  261. {
  262. struct program *pr;
  263. SWIG_InitializeModule(0);
  264. %}
  265. /* pike keywords */
  266. %include <pikekw.swg>