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