From cf056bace78fc04f2a18867894d8dbb72f8cb9d6 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 30 Mar 2005 18:45:01 +0000 Subject: [PATCH] Fix boolean semantics so that the empty string evaluates to false, and numeric strings are false if their numeric values are false. --- simgear/nasal/code.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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; } -- 2.39.5