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.
7 * Swig typemap library for Tcl8. This file contains various sorts
8 * of typemaps for modifying Swig's code generation.
9 * ----------------------------------------------------------------------------- */
11 #if !defined(SWIG_USE_OLD_TYPEMAPS)
12 %include <typemaps/typemaps.swg>
16 The SWIG typemap library provides a language independent mechanism for
17 supporting output arguments, input values, and other C function
18 calling mechanisms. The primary use of the library is to provide a
19 better interface to certain C function--especially those involving
24 // These remap a C pointer to be an "INPUT" value which is passed by value
25 // instead of reference.
28 The following methods can be applied to turn a pointer into a simple
29 "input" value. That is, instead of passing a pointer to an object,
30 you would use a real value instead.
39 unsigned long long *INPUT
45 To use these, suppose you had a C function like this :
47 double fadd(double *a, double *b) {
51 You could wrap it with SWIG as follows :
54 double fadd(double *INPUT, double *INPUT);
56 or you can use the %apply directive :
59 %apply double *INPUT { double *a, double *b };
60 double fadd(double *a, double *b);
64 %typemap(in) double *INPUT(double temp), double &INPUT(double temp)
66 if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) {
72 %typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp)
74 if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) {
77 temp = (float) dvalue;
81 %typemap(in) int *INPUT(int temp), int &INPUT(int temp)
83 if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) {
89 %typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp)
91 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
94 temp = (short) ivalue;
98 %typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp)
100 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
103 temp = (long) ivalue;
107 %typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp),
108 unsigned int &INPUT(int ivalue, unsigned int temp)
110 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
113 temp = (unsigned int) ivalue;
117 %typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp),
118 unsigned short &INPUT(int ivalue, unsigned short temp)
120 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
123 temp = (unsigned short) ivalue;
127 %typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp),
128 unsigned long &INPUT(int ivalue, unsigned long temp)
130 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
133 temp = (unsigned long) ivalue;
137 %typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp),
138 unsigned char &INPUT(int ivalue, unsigned char temp)
140 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
143 temp = (unsigned char) ivalue;
147 %typemap(in) signed char *INPUT(int ivalue, signed char temp),
148 signed char &INPUT(int ivalue, signed char temp)
150 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
153 temp = (signed char) ivalue;
157 %typemap(in) bool *INPUT(int ivalue, bool temp),
158 bool &INPUT(int ivalue, bool temp)
160 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
163 temp = ivalue ? true : false;
167 %typemap(in) long long *INPUT($*1_ltype temp),
168 long long &INPUT($*1_ltype temp)
170 temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);
174 %typemap(in) unsigned long long *INPUT($*1_ltype temp),
175 unsigned long long &INPUT($*1_ltype temp)
177 temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);
181 // OUTPUT typemaps. These typemaps are used for parameters that
182 // are output only. The output value is appended to the result as
186 The following methods can be applied to turn a pointer into an "output"
187 value. When calling a function, no input value would be given for
188 a parameter, but an output value would be returned. In the case of
189 multiple output values, they are returned in the form of a Tcl list.
196 unsigned short *OUTPUT
197 unsigned long *OUTPUT
198 unsigned long long *OUTPUT
199 unsigned char *OUTPUT
204 For example, suppose you were trying to wrap the modf() function in the
205 C math library which splits x into integral and fractional parts (and
206 returns the integer part in one of its parameters).K:
208 double modf(double x, double *ip);
210 You could wrap it with SWIG as follows :
213 double modf(double x, double *OUTPUT);
215 or you can use the %apply directive :
218 %apply double *OUTPUT { double *ip };
219 double modf(double x, double *ip);
221 The Tcl output of the function would be a list containing both
226 %typemap(in,numinputs=0) int *OUTPUT(int temp),
227 short *OUTPUT(short temp),
228 long *OUTPUT(long temp),
229 unsigned int *OUTPUT(unsigned int temp),
230 unsigned short *OUTPUT(unsigned short temp),
231 unsigned long *OUTPUT(unsigned long temp),
232 unsigned char *OUTPUT(unsigned char temp),
233 signed char *OUTPUT(signed char temp),
234 bool *OUTPUT(bool temp),
235 float *OUTPUT(float temp),
236 double *OUTPUT(double temp),
237 long long *OUTPUT($*1_ltype temp),
238 unsigned long long *OUTPUT($*1_ltype temp),
239 int &OUTPUT(int temp),
240 short &OUTPUT(short temp),
241 long &OUTPUT(long temp),
242 unsigned int &OUTPUT(unsigned int temp),
243 unsigned short &OUTPUT(unsigned short temp),
244 unsigned long &OUTPUT(unsigned long temp),
245 signed char &OUTPUT(signed char temp),
246 bool &OUTPUT(bool temp),
247 unsigned char &OUTPUT(unsigned char temp),
248 float &OUTPUT(float temp),
249 double &OUTPUT(double temp),
250 long long &OUTPUT($*1_ltype temp),
251 unsigned long long &OUTPUT($*1_ltype temp)
254 %typemap(argout) int *OUTPUT, int &OUTPUT,
255 short *OUTPUT, short &OUTPUT,
256 long *OUTPUT, long &OUTPUT,
257 unsigned int *OUTPUT, unsigned int &OUTPUT,
258 unsigned short *OUTPUT, unsigned short &OUTPUT,
259 unsigned long *OUTPUT, unsigned long &OUTPUT,
260 unsigned char *OUTPUT, unsigned char &OUTPUT,
261 signed char *OUTPUT, signed char &OUTPUT,
262 bool *OUTPUT, bool &OUTPUT
265 o = Tcl_NewIntObj((int) *($1));
266 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
269 %typemap(argout) float *OUTPUT, float &OUTPUT,
270 double *OUTPUT, double &OUTPUT
273 o = Tcl_NewDoubleObj((double) *($1));
274 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
277 %typemap(argout) long long *OUTPUT, long long &OUTPUT
281 sprintf(temp,"%lld",(long long)*($1));
282 o = Tcl_NewStringObj(temp,-1);
283 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
286 %typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT
290 sprintf(temp,"%llu",(unsigned long long)*($1));
291 o = Tcl_NewStringObj(temp,-1);
292 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
296 // Mappings for an argument that is both an input and output
300 The following methods can be applied to make a function parameter both
301 an input and output value. This combines the behavior of both the
302 "INPUT" and "OUTPUT" methods described earlier. Output values are
303 returned in the form of a Tcl list.
310 unsigned short *INOUT
312 unsigned long long *INOUT
318 For example, suppose you were trying to wrap the following function :
320 void neg(double *x) {
324 You could wrap it with SWIG as follows :
327 void neg(double *INOUT);
329 or you can use the %apply directive :
332 %apply double *INOUT { double *x };
335 Unlike C, this mapping does not directly modify the input value (since
336 this makes no sense in Tcl). Rather, the modified input value shows
337 up as the return value of the function. Thus, to apply this function
338 to a Tcl variable you might do this :
345 %typemap(in) int *INOUT = int *INPUT;
346 %typemap(in) short *INOUT = short *INPUT;
347 %typemap(in) long *INOUT = long *INPUT;
348 %typemap(in) unsigned int *INOUT = unsigned int *INPUT;
349 %typemap(in) unsigned short *INOUT = unsigned short *INPUT;
350 %typemap(in) unsigned long *INOUT = unsigned long *INPUT;
351 %typemap(in) unsigned char *INOUT = unsigned char *INPUT;
352 %typemap(in) signed char *INOUT = signed char *INPUT;
353 %typemap(in) bool *INOUT = bool *INPUT;
354 %typemap(in) float *INOUT = float *INPUT;
355 %typemap(in) double *INOUT = double *INPUT;
356 %typemap(in) long long *INOUT = long long *INPUT;
357 %typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
359 %typemap(in) int &INOUT = int &INPUT;
360 %typemap(in) short &INOUT = short &INPUT;
361 %typemap(in) long &INOUT = long &INPUT;
362 %typemap(in) unsigned int &INOUT = unsigned int &INPUT;
363 %typemap(in) unsigned short &INOUT = unsigned short &INPUT;
364 %typemap(in) unsigned long &INOUT = unsigned long &INPUT;
365 %typemap(in) unsigned char &INOUT = unsigned char &INPUT;
366 %typemap(in) signed char &INOUT = signed char &INPUT;
367 %typemap(in) bool &INOUT = bool &INPUT;
368 %typemap(in) float &INOUT = float &INPUT;
369 %typemap(in) double &INOUT = double &INPUT;
370 %typemap(in) long long &INOUT = long long &INPUT;
371 %typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
373 %typemap(argout) int *INOUT = int *OUTPUT;
374 %typemap(argout) short *INOUT = short *OUTPUT;
375 %typemap(argout) long *INOUT = long *OUTPUT;
376 %typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT;
377 %typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
378 %typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
379 %typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
380 %typemap(argout) signed char *INOUT = signed char *OUTPUT;
381 %typemap(argout) bool *INOUT = bool *OUTPUT;
382 %typemap(argout) float *INOUT = float *OUTPUT;
383 %typemap(argout) double *INOUT = double *OUTPUT;
384 %typemap(argout) long long *INOUT = long long *OUTPUT;
385 %typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
387 %typemap(argout) int &INOUT = int &OUTPUT;
388 %typemap(argout) short &INOUT = short &OUTPUT;
389 %typemap(argout) long &INOUT = long &OUTPUT;
390 %typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT;
391 %typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
392 %typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
393 %typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
394 %typemap(argout) signed char &INOUT = signed char &OUTPUT;
395 %typemap(argout) bool &INOUT = bool &OUTPUT;
396 %typemap(argout) float &INOUT = float &OUTPUT;
397 %typemap(argout) double &INOUT = double &OUTPUT;
398 %typemap(argout) long long &INOUT = long long &OUTPUT;
399 %typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
402 /* Overloading information */
404 %typemap(typecheck) double *INPUT = double;
405 %typemap(typecheck) bool *INPUT = bool;
406 %typemap(typecheck) signed char *INPUT = signed char;
407 %typemap(typecheck) unsigned char *INPUT = unsigned char;
408 %typemap(typecheck) unsigned long *INPUT = unsigned long;
409 %typemap(typecheck) unsigned short *INPUT = unsigned short;
410 %typemap(typecheck) unsigned int *INPUT = unsigned int;
411 %typemap(typecheck) long *INPUT = long;
412 %typemap(typecheck) short *INPUT = short;
413 %typemap(typecheck) int *INPUT = int;
414 %typemap(typecheck) float *INPUT = float;
415 %typemap(typecheck) long long *INPUT = long long;
416 %typemap(typecheck) unsigned long long *INPUT = unsigned long long;
418 %typemap(typecheck) double &INPUT = double;
419 %typemap(typecheck) bool &INPUT = bool;
420 %typemap(typecheck) signed char &INPUT = signed char;
421 %typemap(typecheck) unsigned char &INPUT = unsigned char;
422 %typemap(typecheck) unsigned long &INPUT = unsigned long;
423 %typemap(typecheck) unsigned short &INPUT = unsigned short;
424 %typemap(typecheck) unsigned int &INPUT = unsigned int;
425 %typemap(typecheck) long &INPUT = long;
426 %typemap(typecheck) short &INPUT = short;
427 %typemap(typecheck) int &INPUT = int;
428 %typemap(typecheck) float &INPUT = float;
429 %typemap(typecheck) long long &INPUT = long long;
430 %typemap(typecheck) unsigned long long &INPUT = unsigned long long;
432 %typemap(typecheck) double *INOUT = double;
433 %typemap(typecheck) bool *INOUT = bool;
434 %typemap(typecheck) signed char *INOUT = signed char;
435 %typemap(typecheck) unsigned char *INOUT = unsigned char;
436 %typemap(typecheck) unsigned long *INOUT = unsigned long;
437 %typemap(typecheck) unsigned short *INOUT = unsigned short;
438 %typemap(typecheck) unsigned int *INOUT = unsigned int;
439 %typemap(typecheck) long *INOUT = long;
440 %typemap(typecheck) short *INOUT = short;
441 %typemap(typecheck) int *INOUT = int;
442 %typemap(typecheck) float *INOUT = float;
443 %typemap(typecheck) long long *INOUT = long long;
444 %typemap(typecheck) unsigned long long *INOUT = unsigned long long;
446 %typemap(typecheck) double &INOUT = double;
447 %typemap(typecheck) bool &INOUT = bool;
448 %typemap(typecheck) signed char &INOUT = signed char;
449 %typemap(typecheck) unsigned char &INOUT = unsigned char;
450 %typemap(typecheck) unsigned long &INOUT = unsigned long;
451 %typemap(typecheck) unsigned short &INOUT = unsigned short;
452 %typemap(typecheck) unsigned int &INOUT = unsigned int;
453 %typemap(typecheck) long &INOUT = long;
454 %typemap(typecheck) short &INOUT = short;
455 %typemap(typecheck) int &INOUT = int;
456 %typemap(typecheck) float &INOUT = float;
457 %typemap(typecheck) long long &INOUT = long long;
458 %typemap(typecheck) unsigned long long &INOUT = unsigned long long;
462 // --------------------------------------------------------------------
464 // --------------------------------------------------------------------
466 %include <tclinterp.i>
467 %include <tclresult.i>