diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-30 13:48:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-30 13:48:44 -0300 |
commit | 5388aa9fc0185b5d7a852e679484e26ba53e5d4d (patch) | |
tree | 2085a65550d299ee37369985f47af4fd9f5c951e /lobject.c | |
parent | b123a88673fcf37ebfcc8ea866a3d27da6cdf82e (diff) | |
download | lua-5388aa9fc0185b5d7a852e679484e26ba53e5d4d.tar.gz lua-5388aa9fc0185b5d7a852e679484e26ba53e5d4d.tar.bz2 lua-5388aa9fc0185b5d7a852e679484e26ba53e5d4d.zip |
'luaO_str2d' + 'luaO_str2int' replaced by 'luaO_str2num' (which converts
to float or integer according to the string syntax)
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.81 2014/04/27 14:41:11 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.82 2014/04/29 18:14:16 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 | */ |
@@ -254,7 +254,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
254 | /* }====================================================== */ | 254 | /* }====================================================== */ |
255 | 255 | ||
256 | 256 | ||
257 | int luaO_str2d (const char *s, size_t len, lua_Number *result) { | 257 | static int l_str2d (const char *s, size_t len, lua_Number *result) { |
258 | char *endptr; | 258 | char *endptr; |
259 | if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ | 259 | if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ |
260 | return 0; | 260 | return 0; |
@@ -268,7 +268,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { | |||
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | int luaO_str2int (const char *s, size_t len, lua_Integer *result) { | 271 | static int l_str2int (const char *s, size_t len, lua_Integer *result) { |
272 | const char *ends = s + len; | 272 | const char *ends = s + len; |
273 | lua_Unsigned a = 0; | 273 | lua_Unsigned a = 0; |
274 | int empty = 1; | 274 | int empty = 1; |
@@ -298,6 +298,20 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) { | |||
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | int luaO_str2num (const char *s, size_t len, TValue *o) { | ||
302 | lua_Integer i; lua_Number n; | ||
303 | if (l_str2int(s, len, &i)) { /* try as an integer */ | ||
304 | setivalue(o, i); | ||
305 | } | ||
306 | else if (l_str2d(s, len, &n)) { /* else try as a float */ | ||
307 | setfltvalue(o, n); | ||
308 | } | ||
309 | else | ||
310 | return 0; /* conversion failed */ | ||
311 | return 1; /* success */ | ||
312 | } | ||
313 | |||
314 | |||
301 | int luaO_utf8esc (char *buff, unsigned int x) { | 315 | int luaO_utf8esc (char *buff, unsigned int x) { |
302 | int n = 1; /* number of bytes put in buffer (backwards) */ | 316 | int n = 1; /* number of bytes put in buffer (backwards) */ |
303 | if (x < 0x80) /* ascii? */ | 317 | if (x < 0x80) /* ascii? */ |