diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -1,11 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.31 1998/07/12 16:16:43 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.32 1998/12/03 15:45:15 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 | */ |
6 | 6 | ||
7 | 7 | ||
8 | #include <ctype.h> | ||
8 | #include <stdio.h> | 9 | #include <stdio.h> |
10 | #include <stdlib.h> | ||
9 | #include <string.h> | 11 | #include <string.h> |
10 | 12 | ||
11 | #include "lauxlib.h" | 13 | #include "lauxlib.h" |
@@ -24,6 +26,7 @@ | |||
24 | 26 | ||
25 | #ifdef OLD_ANSI | 27 | #ifdef OLD_ANSI |
26 | #define strcoll(a,b) strcmp(a,b) | 28 | #define strcoll(a,b) strcmp(a,b) |
29 | double strtod(); | ||
27 | #endif | 30 | #endif |
28 | 31 | ||
29 | 32 | ||
@@ -48,19 +51,19 @@ static TaggedString *strconc (TaggedString *l, TaggedString *r) | |||
48 | } | 51 | } |
49 | 52 | ||
50 | 53 | ||
51 | int luaV_tonumber (TObject *obj) | 54 | int luaV_tonumber (TObject *obj) { |
52 | { /* LUA_NUMBER */ | 55 | /* LUA_NUMBER */ |
53 | double t; | ||
54 | char c; | ||
55 | if (ttype(obj) != LUA_T_STRING) | 56 | if (ttype(obj) != LUA_T_STRING) |
56 | return 1; | 57 | return 1; |
57 | else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) { | 58 | else { |
59 | char *e; | ||
60 | double t = strtod(svalue(obj), &e); | ||
61 | while (isspace(*e)) e++; | ||
62 | if (*e != '\0') return 2; | ||
58 | nvalue(obj) = (real)t; | 63 | nvalue(obj) = (real)t; |
59 | ttype(obj) = LUA_T_NUMBER; | 64 | ttype(obj) = LUA_T_NUMBER; |
60 | return 0; | 65 | return 0; |
61 | } | 66 | } |
62 | else | ||
63 | return 2; | ||
64 | } | 67 | } |
65 | 68 | ||
66 | 69 | ||