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