aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 384f77c0..b7365f66 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -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