X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fstring.c;h=ce8b5ac252721919a91293196b8ba29b277d1604;hb=ceae2928aab1ce54412e8f45af93d57b1147bee5;hp=65a29526c97ce0db31a08c87b0d48a08f6edf64c;hpb=dd1ea541ecc4403bcea2ca8c60c03971d1f4338f;p=simgear.git diff --git a/simgear/nasal/string.c b/simgear/nasal/string.c index 65a29526..ce8b5ac2 100644 --- a/simgear/nasal/string.c +++ b/simgear/nasal/string.c @@ -185,9 +185,7 @@ static int tonum(unsigned char* s, int len, double* result) int i=0, fraclen=0; double sgn=1, val, frac=0, exp=0; - // Special case, "." is not a number, even though "1." and ".0" are. - if(len == 1 && s[0] == '.') - return 0; + if(len == 1 && (*s=='.' || *s=='-' || *s=='+')) return 0; // Strip off the leading negative sign first, so we can correctly // parse things like -.xxx which would otherwise confuse @@ -322,3 +320,27 @@ static int fromnum(double val, unsigned char* s) *ptr = 0; return ptr - s; } + + +//------------------------------------------------------------------------------ +static naRef string_methods; +static int init = 0; // As we can't use naNil() for static initialization we + // need a separate variable for saving whether we have + // already initialized. + +//------------------------------------------------------------------------------ +naRef naInit_string(naContext c) +{ + string_methods = naNewHash(c); + init = 1; + return string_methods; +} + +//------------------------------------------------------------------------------ +naRef getStringMethods(naContext c) +{ + if( !init ) + return naNil(); + + return string_methods; +}