diff options
| -rw-r--r-- | llex.c | 5 | ||||
| -rw-r--r-- | lobject.c | 33 | ||||
| -rw-r--r-- | lobject.h | 4 |
3 files changed, 27 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.64 2013/04/16 18:46:28 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.65 2013/04/26 13:07:53 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 | */ |
| @@ -248,7 +248,8 @@ static int read_numeral (LexState *ls, SemInfo *seminfo, int isf) { | |||
| 248 | } | 248 | } |
| 249 | save(ls, '\0'); | 249 | save(ls, '\0'); |
| 250 | if (!isf) { | 250 | if (!isf) { |
| 251 | if (!luaO_str2int(luaZ_buffer(ls->buff), &seminfo->i)) | 251 | if (!luaO_str2int(luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff) - 1, |
| 252 | &seminfo->i)) | ||
| 252 | lexerror(ls, "malformed number", TK_INT); | 253 | lexerror(ls, "malformed number", TK_INT); |
| 253 | return TK_INT; | 254 | return TK_INT; |
| 254 | } | 255 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.61 2013/04/29 16:57:28 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.62 2013/05/02 12:37:24 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -133,11 +133,6 @@ int luaO_hexavalue (int c) { | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | #if !defined(lua_strx2number) | ||
| 137 | |||
| 138 | #include <math.h> | ||
| 139 | |||
| 140 | |||
| 141 | static int isneg (const char **s) { | 136 | static int isneg (const char **s) { |
| 142 | if (**s == '-') { (*s)++; return 1; } | 137 | if (**s == '-') { (*s)++; return 1; } |
| 143 | else if (**s == '+') (*s)++; | 138 | else if (**s == '+') (*s)++; |
| @@ -145,6 +140,11 @@ static int isneg (const char **s) { | |||
| 145 | } | 140 | } |
| 146 | 141 | ||
| 147 | 142 | ||
| 143 | #if !defined(lua_strx2number) | ||
| 144 | |||
| 145 | #include <math.h> | ||
| 146 | |||
| 147 | |||
| 148 | static lua_Number readhexa (const char **s, lua_Number r, int *count) { | 148 | static lua_Number readhexa (const char **s, lua_Number r, int *count) { |
| 149 | for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */ | 149 | for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */ |
| 150 | r = (r * cast_num(16.0)) + cast_num(luaO_hexavalue(cast_uchar(**s))); | 150 | r = (r * cast_num(16.0)) + cast_num(luaO_hexavalue(cast_uchar(**s))); |
| @@ -212,21 +212,32 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | 214 | ||
| 215 | int luaO_str2int (const char *s, lua_Integer *result) { | 215 | int luaO_str2int (const char *s, size_t len, lua_Integer *result) { |
| 216 | const char *ends = s + len; | ||
| 216 | lua_Unsigned a = 0; | 217 | lua_Unsigned a = 0; |
| 218 | int empty = 1; | ||
| 219 | int neg; | ||
| 220 | while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ | ||
| 221 | neg = isneg(&s); | ||
| 217 | if (s[0] == '0' && | 222 | if (s[0] == '0' && |
| 218 | (s[1] == 'x' || s[1] == 'X')) { /* hexa? */ | 223 | (s[1] == 'x' || s[1] == 'X')) { /* hexa? */ |
| 219 | s += 2; /* skip '0x' */ | 224 | s += 2; /* skip '0x' */ |
| 220 | for (; lisxdigit(cast_uchar(*s)); s++) | 225 | for (; lisxdigit(cast_uchar(*s)); s++) { |
| 221 | a = a * 16 + luaO_hexavalue(cast_uchar(*s)); | 226 | a = a * 16 + luaO_hexavalue(cast_uchar(*s)); |
| 227 | empty = 0; | ||
| 228 | } | ||
| 222 | } | 229 | } |
| 223 | else { /* decimal */ | 230 | else { /* decimal */ |
| 224 | for (; lisdigit(cast_uchar(*s)); s++) | 231 | for (; lisdigit(cast_uchar(*s)); s++) { |
| 225 | a = a * 10 + luaO_hexavalue(cast_uchar(*s)); | 232 | a = a * 10 + luaO_hexavalue(cast_uchar(*s)); |
| 233 | empty = 0; | ||
| 234 | } | ||
| 226 | } | 235 | } |
| 227 | if (*s != '\0') return 0; /* something wrong in the numeral */ | 236 | while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ |
| 237 | if (empty || s != ends) return 0; /* something wrong in the numeral */ | ||
| 228 | else { | 238 | else { |
| 229 | *result = cast(lua_Integer, a); | 239 | if (neg) *result = -cast(lua_Integer, a); |
| 240 | else *result = cast(lua_Integer, a); | ||
| 230 | return 1; | 241 | return 1; |
| 231 | } | 242 | } |
| 232 | } | 243 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.76 2013/05/02 12:37:24 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.77 2013/05/06 17:17:09 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 | */ |
| @@ -496,7 +496,7 @@ LUAI_FUNC int luaO_ceillog2 (unsigned int x); | |||
| 496 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, | 496 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, |
| 497 | const TValue *p2, TValue *res); | 497 | const TValue *p2, TValue *res); |
| 498 | LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result); | 498 | LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result); |
| 499 | LUAI_FUNC int luaO_str2int (const char *s, lua_Integer *result); | 499 | LUAI_FUNC int luaO_str2int (const char *s, size_t len, lua_Integer *result); |
| 500 | LUAI_FUNC int luaO_hexavalue (int c); | 500 | LUAI_FUNC int luaO_hexavalue (int c); |
| 501 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 501 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
| 502 | va_list argp); | 502 | va_list argp); |
