diff options
Diffstat (limited to 'opcode.c')
| -rw-r--r-- | opcode.c | 26 |
1 files changed, 15 insertions, 11 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 3.77 1996/11/18 13:48:44 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.78 1996/11/22 13:08:28 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -157,16 +157,20 @@ static int lua_tonumber (Object *obj) | |||
| 157 | */ | 157 | */ |
| 158 | static int lua_tostring (Object *obj) | 158 | static int lua_tostring (Object *obj) |
| 159 | { | 159 | { |
| 160 | char s[256]; | 160 | if (tag(obj) != LUA_T_NUMBER) |
| 161 | if (tag(obj) != LUA_T_NUMBER) | 161 | return 1; |
| 162 | return 1; | 162 | else { |
| 163 | if ((int) nvalue(obj) == nvalue(obj)) | 163 | char s[60]; |
| 164 | sprintf (s, "%d", (int) nvalue(obj)); | 164 | real f = nvalue(obj); |
| 165 | else | 165 | int i; |
| 166 | sprintf (s, "%g", nvalue(obj)); | 166 | if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) |
| 167 | tsvalue(obj) = lua_createstring(s); | 167 | sprintf (s, "%d", i); |
| 168 | tag(obj) = LUA_T_STRING; | 168 | else |
| 169 | return 0; | 169 | sprintf (s, "%g", nvalue(obj)); |
| 170 | tsvalue(obj) = lua_createstring(s); | ||
| 171 | tag(obj) = LUA_T_STRING; | ||
| 172 | return 0; | ||
| 173 | } | ||
| 170 | } | 174 | } |
| 171 | 175 | ||
| 172 | 176 | ||
