From 5388aa9fc0185b5d7a852e679484e26ba53e5d4d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 30 Apr 2014 13:48:44 -0300 Subject: 'luaO_str2d' + 'luaO_str2int' replaced by 'luaO_str2num' (which converts to float or integer according to the string syntax) --- lobject.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lobject.c') diff --git a/lobject.c b/lobject.c index 6034feaf..a95948f5 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.81 2014/04/27 14:41:11 roberto Exp roberto $ +** $Id: lobject.c,v 2.82 2014/04/29 18:14:16 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -254,7 +254,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { /* }====================================================== */ -int luaO_str2d (const char *s, size_t len, lua_Number *result) { +static int l_str2d (const char *s, size_t len, lua_Number *result) { char *endptr; if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ return 0; @@ -268,7 +268,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { } -int luaO_str2int (const char *s, size_t len, lua_Integer *result) { +static int l_str2int (const char *s, size_t len, lua_Integer *result) { const char *ends = s + len; lua_Unsigned a = 0; int empty = 1; @@ -298,6 +298,20 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) { } +int luaO_str2num (const char *s, size_t len, TValue *o) { + lua_Integer i; lua_Number n; + if (l_str2int(s, len, &i)) { /* try as an integer */ + setivalue(o, i); + } + else if (l_str2d(s, len, &n)) { /* else try as a float */ + setfltvalue(o, n); + } + else + return 0; /* conversion failed */ + return 1; /* success */ +} + + int luaO_utf8esc (char *buff, unsigned int x) { int n = 1; /* number of bytes put in buffer (backwards) */ if (x < 0x80) /* ascii? */ -- cgit v1.2.3-55-g6feb