tonumber'e1' and tonumber(' ', x), for x!=10, gave 0 instead of nil.

This commit is contained in:
Roberto Ierusalimschy
1999-09-08 17:45:18 -03:00
parent 2e13cd77ab
commit ae3ecc2d4a
3 changed files with 27 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $
** $Id: lbuiltin.c,v 1.61 1999/08/16 20:52:00 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@@ -146,13 +146,15 @@ static void luaB_tonumber (void) {
else lua_pushnil(); /* not a number */
}
else {
char *s;
long n;
const char *s1 = luaL_check_string(1);
char *s2;
real n;
luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
n = strtol(luaL_check_string(1), &s, base);
while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */
if (*s) lua_pushnil(); /* invalid format: return nil */
else lua_pushnumber(n);
n = strtoul(s1, &s2, base);
if (s1 == s2) return; /* no valid digits: return nil */
while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */
if (*s2) return; /* invalid trailing character: return nil */
lua_pushnumber(n);
}
}