From be2645fa5077ea36a42353508bbef46e0cea9e57 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Feb 2003 22:33:53 +0000 Subject: [PATCH] bool mods for Visual C++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4285 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/tcl/tcl8.swg | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/SWIG/Lib/tcl/tcl8.swg b/SWIG/Lib/tcl/tcl8.swg index 06e73726a..6dff5cdc6 100644 --- a/SWIG/Lib/tcl/tcl8.swg +++ b/SWIG/Lib/tcl/tcl8.swg @@ -39,7 +39,7 @@ is no guarantee that a bool is the same size as an int so we have to do this */ %typemap(in) bool (int tempb) "if (Tcl_GetIntFromObj(interp,$input,&tempb) == TCL_ERROR) SWIG_fail; - $1 = (bool) tempb;"; + $1 = tempb ? true : false;"; /* These will pass an integer as an unsigned long. However, the implementation is crippled due to limited precision in Tcl */ @@ -83,8 +83,7 @@ const unsigned short & (unsigned short temp), const unsigned long & (unsigned long temp), const signed char & (signed char temp), - const unsigned char & (unsigned char temp), - const bool & (bool temp) + const unsigned char & (unsigned char temp) { long ltemp; if (Tcl_GetLongFromObj(interp, $input, <emp) != TCL_OK) { @@ -94,6 +93,17 @@ $1 = &temp; } +%typemap(in) const bool & (bool temp) +{ + long ltemp; + if (Tcl_GetLongFromObj(interp, $input, <emp) != TCL_OK) { + SWIG_fail; + } + temp = ltemp ? true : false; + $1 = &temp; +} + + %typemap(in) const float & (float temp), const double & (double temp) { @@ -270,7 +280,7 @@ /* -- Variable input --- */ -%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, bool, enum SWIGTYPE +%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE { long temp; if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) { @@ -279,6 +289,15 @@ $1 = ($1_type) temp; } +%typemap(varin) bool +{ + long temp; + if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) { + return (char*) "Type error. expected an integer"; + } + $1 = temp ? true : false; +} + %typemap(varin) long long "$1 = (long long) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);"; %typemap(varin) unsigned long long "$1 = (unsigned long long) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);"; @@ -433,7 +452,7 @@ const unsigned int &, const unsigned short &, const unsigned long &, const long long &, const unsigned long long &, enum SWIGTYPE, - bool, const bool & + bool, const bool & { long tmp; if (Tcl_GetLongFromObj(NULL,$input,&tmp) == TCL_ERROR) $1 = 0;