add native bool support
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8345 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c6baa21db4
commit
75d64a4018
3 changed files with 53 additions and 0 deletions
|
|
@ -108,6 +108,14 @@ static char *bar(void *) {
|
|||
};
|
||||
|
||||
|
||||
bool fbool(bool b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
int fbool(int b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
char *fint(int) {
|
||||
return (char*) "fint:int";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,3 +286,12 @@ if (!(overload_simple::fid("3.0", "3.0") eq "fid:doubledouble")) {
|
|||
if (!(overload_simple::fid("3", 3) eq "fid:intint")) {
|
||||
die("fid(int,int)");
|
||||
}
|
||||
|
||||
|
||||
if (!(overload_simple::fbool(0)) != overload_simple::fbool(1)) {
|
||||
die("fbool(bool)");
|
||||
}
|
||||
|
||||
if (2 != overload_simple::fbool(2)) {
|
||||
die("fbool(int)");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,42 @@
|
|||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* bool */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE SV *
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
SV *obj = sv_newmortal();
|
||||
if (value) {
|
||||
sv_setsv(obj, &PL_sv_yes);
|
||||
} else {
|
||||
sv_setsv(obj, &PL_sv_no);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment="SWIG_CanCastAsInteger") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(bool)(SV *obj, bool* val)
|
||||
{
|
||||
if (obj == &PL_sv_yes) {
|
||||
if (val) *val = true;
|
||||
return SWIG_OK;
|
||||
} else if (obj == &PL_sv_no) {
|
||||
if (val) *val = false;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (val) *val = SvTRUE(obj) ? true: false;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* long */
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue