diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-09-08 17:45:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-09-08 17:45:18 -0300 |
commit | ae3ecc2d4a5b108efbb2bd3db9f8e902f28de21d (patch) | |
tree | 7841fe86bc11cb386d8b51c7020ce308dc0ec175 /lbuiltin.c | |
parent | 2e13cd77ab3b3719ef139e4786328be813fb10e0 (diff) | |
download | lua-ae3ecc2d4a5b108efbb2bd3db9f8e902f28de21d.tar.gz lua-ae3ecc2d4a5b108efbb2bd3db9f8e902f28de21d.tar.bz2 lua-ae3ecc2d4a5b108efbb2bd3db9f8e902f28de21d.zip |
tonumber'e1' and tonumber(' ', x), for x!=10, gave 0 instead of nil.
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.61 1999/08/16 20:52:00 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -146,13 +146,15 @@ static void luaB_tonumber (void) { | |||
146 | else lua_pushnil(); /* not a number */ | 146 | else lua_pushnil(); /* not a number */ |
147 | } | 147 | } |
148 | else { | 148 | else { |
149 | char *s; | 149 | const char *s1 = luaL_check_string(1); |
150 | long n; | 150 | char *s2; |
151 | real n; | ||
151 | luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); | 152 | luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); |
152 | n = strtol(luaL_check_string(1), &s, base); | 153 | n = strtoul(s1, &s2, base); |
153 | while (isspace((unsigned char)*s)) s++; /* skip trailing spaces */ | 154 | if (s1 == s2) return; /* no valid digits: return nil */ |
154 | if (*s) lua_pushnil(); /* invalid format: return nil */ | 155 | while (isspace((unsigned char)*s2)) s2++; /* skip trailing spaces */ |
155 | else lua_pushnumber(n); | 156 | if (*s2) return; /* invalid trailing character: return nil */ |
157 | lua_pushnumber(n); | ||
156 | } | 158 | } |
157 | } | 159 | } |
158 | 160 | ||