diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-09-06 17:34:18 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-09-06 17:34:18 -0300 |
commit | 2e13cd77ab3b3719ef139e4786328be813fb10e0 (patch) | |
tree | 17717c1015f20dff2ac62cfd2a082c4aba5ab206 | |
parent | ff9c0da7839543478d62306dd208f11caab130c1 (diff) | |
download | lua-2e13cd77ab3b3719ef139e4786328be813fb10e0.tar.gz lua-2e13cd77ab3b3719ef139e4786328be813fb10e0.tar.bz2 lua-2e13cd77ab3b3719ef139e4786328be813fb10e0.zip |
new interface for `luaO_strtod', which now checks signal, too.
-rw-r--r-- | llex.c | 5 | ||||
-rw-r--r-- | lobject.h | 4 | ||||
-rw-r--r-- | lundump.c | 12 | ||||
-rw-r--r-- | lvm.c | 17 |
4 files changed, 12 insertions, 26 deletions
@@ -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 | ||
@@ -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; | |||
190 | int luaO_equalval (const TObject *t1, const TObject *t2); | 190 | int luaO_equalval (const TObject *t1, const TObject *t2); |
191 | int luaO_redimension (int oldsize); | 191 | int luaO_redimension (int oldsize); |
192 | void luaO_insertlist (GCnode *root, GCnode *node); | 192 | void luaO_insertlist (GCnode *root, GCnode *node); |
193 | double luaO_str2d (const char *s); | 193 | int luaO_str2d (const char *s, real *result); |
194 | 194 | ||
195 | #ifdef OLD_ANSI | 195 | #ifdef OLD_ANSI |
196 | void luaO_memup (void *dest, void *src, int size); | 196 | void luaO_memup (void *dest, void *src, int size); |
@@ -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 | */ |
53 | double luaU_str2d (const char* b, const char* where) | 53 | real 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 | ||
61 | static real LoadNumber (ZIO* Z, int native) | 61 | static real LoadNumber (ZIO* Z, int native) |
@@ -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 | } |