diff options
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.57 2013/01/29 16:00:40 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.58 2013/02/20 14:08:56 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 | */ |
@@ -169,6 +169,25 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | int luaO_str2int (const char *s, lua_Integer *result) { | ||
173 | lua_Unsigned a = 0; | ||
174 | if (s[0] == '0' && | ||
175 | (s[1] == 'x' || s[1] == 'X')) { /* hexa? */ | ||
176 | s += 2; /* skip '0x' */ | ||
177 | for (; lisxdigit(cast_uchar(*s)); s++) | ||
178 | a = a * 16 + luaO_hexavalue(cast_uchar(*s)); | ||
179 | } | ||
180 | else { /* decimal */ | ||
181 | for (; lisdigit(cast_uchar(*s)); s++) | ||
182 | a = a * 10 + luaO_hexavalue(cast_uchar(*s)); | ||
183 | } | ||
184 | if (*s != '\0') return 0; /* something wrong in the numeral */ | ||
185 | else { | ||
186 | *result = cast(lua_Integer, a); | ||
187 | return 1; | ||
188 | } | ||
189 | } | ||
190 | |||
172 | 191 | ||
173 | static void pushstr (lua_State *L, const char *str, size_t l) { | 192 | static void pushstr (lua_State *L, const char *str, size_t l) { |
174 | setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); | 193 | setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); |