complete support for hexadecimal constants

This commit is contained in:
Roberto Ierusalimschy 2006-02-10 15:43:52 -02:00
parent 6316a866a3
commit 298ae7e230
1 changed files with 3 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 2.20 2005/12/22 16:19:56 roberto Exp roberto $
** $Id: lobject.c,v 2.21 2006/01/10 12:50:00 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -91,6 +91,8 @@ int luaO_str2d (const char *s, lua_Number *result) {
char *endptr;
*result = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* conversion failed */
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
*result = cast_num(strtoul(s, &endptr, 16));
if (*endptr == '\0') return 1; /* most common case */
while (isspace(cast(unsigned char, *endptr))) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */