diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-30 11:00:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-30 11:00:14 -0300 |
commit | 34ac039fb84e3c12fb8c96c9c99c34224c09872b (patch) | |
tree | a859f6338c6c851088a67b129765de662ed6f223 /lapi.c | |
parent | 1aa526263405fb4906eafab3011b13de4e5daf73 (diff) | |
download | lua-github-34ac039fb84e3c12fb8c96c9c99c34224c09872b.tar.gz |
new macro 'cvt2str' to better control whether numbers are convertible
to strings
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.230 2014/07/21 16:02:57 roberto Exp roberto $ +** $Id: lapi.c,v 2.231 2014/07/22 18:07:47 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -279,8 +279,8 @@ LUA_API int lua_isnumber (lua_State *L, int idx) { LUA_API int lua_isstring (lua_State *L, int idx) { - int t = lua_type(L, idx); - return (t == LUA_TSTRING || t == LUA_TNUMBER); + const TValue *o = index2addr(L, idx); + return (ttisstring(o) || cvt2str(o)); } @@ -371,14 +371,14 @@ LUA_API int lua_toboolean (lua_State *L, int idx) { LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { StkId o = index2addr(L, idx); if (!ttisstring(o)) { - lua_lock(L); /* `luaV_tostring' may create a new string */ - if (!luaV_tostring(L, o)) { /* conversion failed? */ + if (!cvt2str(o)) { /* not convertible? */ if (len != NULL) *len = 0; - lua_unlock(L); return NULL; } + lua_lock(L); /* `luaO_tostring' may create a new string */ luaC_checkGC(L); o = index2addr(L, idx); /* previous call may reallocate the stack */ + luaO_tostring(L, o); lua_unlock(L); } if (len != NULL) *len = tsvalue(o)->len; |