From: andy Date: Wed, 30 Mar 2005 18:45:01 +0000 (+0000) Subject: Fix boolean semantics so that the empty string evaluates to false, and X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cf056bace78fc04f2a18867894d8dbb72f8cb9d6;p=simgear.git Fix boolean semantics so that the empty string evaluates to false, and numeric strings are false if their numeric values are false. --- diff --git a/simgear/nasal/code.c b/simgear/nasal/code.c index 388c4eae..d5428364 100644 --- a/simgear/nasal/code.c +++ b/simgear/nasal/code.c @@ -27,11 +27,16 @@ void naRuntimeError(struct Context* c, char* msg) longjmp(c->jumpHandle, 1); } -int boolify(struct Context* ctx, naRef r) +static int boolify(struct Context* ctx, naRef r) { - if(IS_NIL(r)) return 0; if(IS_NUM(r)) return r.num != 0; - if(IS_STR(r)) return 1; + if(IS_NIL(r)) return 0; + if(IS_STR(r)) { + double d; + if(naStr_len(r) == 0) return 0; + if(naStr_tonum(r, &d)) return d != 0; + else return 1; + } ERR(ctx, "non-scalar used in boolean context"); return 0; }