aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-09-06 17:34:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-09-06 17:34:18 -0300
commit2e13cd77ab3b3719ef139e4786328be813fb10e0 (patch)
tree17717c1015f20dff2ac62cfd2a082c4aba5ab206
parentff9c0da7839543478d62306dd208f11caab130c1 (diff)
downloadlua-2e13cd77ab3b3719ef139e4786328be813fb10e0.tar.gz
lua-2e13cd77ab3b3719ef139e4786328be813fb10e0.tar.bz2
lua-2e13cd77ab3b3719ef139e4786328be813fb10e0.zip
new interface for `luaO_strtod', which now checks signal, too.
-rw-r--r--llex.c5
-rw-r--r--lobject.h4
-rw-r--r--lundump.c12
-rw-r--r--lvm.c17
4 files changed, 12 insertions, 26 deletions
diff --git a/llex.c b/llex.c
index 63404c3d..09891b61 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.37 1999/07/22 19:29:42 roberto Exp roberto $ 2** $Id: llex.c,v 1.38 1999/08/16 20:52:00 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -402,8 +402,7 @@ int luaX_lex (LexState *LS) {
402 save_and_next(LS); 402 save_and_next(LS);
403 } 403 }
404 save('\0'); 404 save('\0');
405 LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase); 405 if (!luaO_str2d(L->Mbuffer+L->Mbuffbase, &LS->seminfo.r))
406 if (LS->seminfo.r < 0)
407 luaX_error(LS, "invalid numeric format"); 406 luaX_error(LS, "invalid numeric format");
408 return NUMBER; 407 return NUMBER;
409 408
diff --git a/lobject.h b/lobject.h
index 91bf0cac..2e69ebf5 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 roberto Exp roberto $ 2** $Id: lobject.h,v 1.29 1999/08/16 20:52:00 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -190,7 +190,7 @@ extern const TObject luaO_nilobject;
190int luaO_equalval (const TObject *t1, const TObject *t2); 190int luaO_equalval (const TObject *t1, const TObject *t2);
191int luaO_redimension (int oldsize); 191int luaO_redimension (int oldsize);
192void luaO_insertlist (GCnode *root, GCnode *node); 192void luaO_insertlist (GCnode *root, GCnode *node);
193double luaO_str2d (const char *s); 193int luaO_str2d (const char *s, real *result);
194 194
195#ifdef OLD_ANSI 195#ifdef OLD_ANSI
196void luaO_memup (void *dest, void *src, int size); 196void luaO_memup (void *dest, void *src, int size);
diff --git a/lundump.c b/lundump.c
index 225eda28..9f6e3dc3 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.12 1999/07/08 12:43:23 roberto Exp roberto $ 2** $Id: lundump.c,v 1.13 1999/08/16 20:52:00 roberto Exp roberto $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,12 +50,12 @@ static unsigned long LoadLong (ZIO* Z)
50/* 50/*
51* convert number from text 51* convert number from text
52*/ 52*/
53double luaU_str2d (const char* b, const char* where) 53real luaU_str2d (const char* b, const char* where)
54{ 54{
55 int negative=(b[0]=='-'); 55 real x;
56 double x=luaO_str2d(b+negative); 56 if (!luaO_str2d(b, &x))
57 if (x<0) luaL_verror("cannot convert number '%s' in %s",b,where); 57 luaL_verror("cannot convert number '%s' in %s",b,where);
58 return negative ? -x : x; 58 return x;
59} 59}
60 60
61static real LoadNumber (ZIO* Z, int native) 61static real LoadNumber (ZIO* Z, int native)
diff --git a/lvm.c b/lvm.c
index 62060d90..fe2dc851 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 roberto Exp roberto $ 2** $Id: lvm.c,v 1.60 1999/08/16 20:52:00 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -53,21 +53,8 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
53 if (ttype(obj) != LUA_T_STRING) 53 if (ttype(obj) != LUA_T_STRING)
54 return 1; 54 return 1;
55 else { 55 else {
56 real t; 56 if (!luaO_str2d(svalue(obj), &nvalue(obj)))
57 char *e = svalue(obj);
58 int sig = 1;
59 while (isspace((unsigned char)*e)) e++;
60 if (*e == '-') {
61 e++;
62 sig = -1;
63 }
64 else if (*e == '+') e++;
65 /* no digit before or after decimal point? */
66 if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1)))
67 return 2; 57 return 2;
68 t = (real)luaO_str2d(e);
69 if (t<0) return 2;
70 nvalue(obj) = t*sig;
71 ttype(obj) = LUA_T_NUMBER; 58 ttype(obj) = LUA_T_NUMBER;
72 return 0; 59 return 0;
73 } 60 }