commit 2e13cd77ab3b3719ef139e4786328be813fb10e0
parent ff9c0da7839543478d62306dd208f11caab130c1
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 6 Sep 1999 17:33:56 -0300
new interface for `luaO_strtod', which now checks signal, too.
Diffstat:
4 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/llex.c b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 1.37 1999/07/22 19:29:42 roberto Exp roberto $
+** $Id: llex.c,v 1.38 1999/08/16 20:52:00 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -402,8 +402,7 @@ int luaX_lex (LexState *LS) {
save_and_next(LS);
}
save('\0');
- LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase);
- if (LS->seminfo.r < 0)
+ if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r))
luaX_error(LS, "invalid numeric format");
return NUMBER;
diff --git a/lobject.h b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 roberto Exp roberto $
+** $Id: lobject.h,v 1.29 1999/08/16 20:52:00 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -190,7 +190,7 @@ extern const TObject luaO_nilobject;
int luaO_equalval (const TObject *t1, const TObject *t2);
int luaO_redimension (int oldsize);
void luaO_insertlist (GCnode *root, GCnode *node);
-double luaO_str2d (const char *s);
+int luaO_str2d (const char *s, real *result);
#ifdef OLD_ANSI
void luaO_memup (void *dest, void *src, int size);
diff --git a/lundump.c b/lundump.c
@@ -1,5 +1,5 @@
/*
-** $Id: lundump.c,v 1.12 1999/07/08 12:43:23 roberto Exp roberto $
+** $Id: lundump.c,v 1.13 1999/08/16 20:52:00 roberto Exp roberto $
** load bytecodes from files
** See Copyright Notice in lua.h
*/
@@ -50,12 +50,12 @@ static unsigned long LoadLong (ZIO* Z)
/*
* convert number from text
*/
-double luaU_str2d (const char* b, const char* where)
+real luaU_str2d (const char* b, const char* where)
{
- int negative=(b[0]=='-');
- double x=luaO_str2d(b+negative);
- if (x<0) luaL_verror("cannot convert number '%s' in %s",b,where);
- return negative ? -x : x;
+ real x;
+ if (!luaO_str2d(b, &x))
+ luaL_verror("cannot convert number '%s' in %s",b,where);
+ return x;
}
static real LoadNumber (ZIO* Z, int native)
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 roberto Exp roberto $
+** $Id: lvm.c,v 1.60 1999/08/16 20:52:00 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -53,21 +53,8 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_STRING)
return 1;
else {
- real t;
- char *e = svalue(obj);
- int sig = 1;
- while (isspace((unsigned char)*e)) e++;
- if (*e == '-') {
- e++;
- sig = -1;
- }
- else if (*e == '+') e++;
- /* no digit before or after decimal point? */
- if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1)))
+ if (!luaO_str2d(svalue(obj), &nvalue(obj)))
return 2;
- t = (real)luaO_str2d(e);
- if (t<0) return 2;
- nvalue(obj) = t*sig;
ttype(obj) = LUA_T_NUMBER;
return 0;
}