aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-30 11:00:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-30 11:00:14 -0300
commit34ac039fb84e3c12fb8c96c9c99c34224c09872b (patch)
treea859f6338c6c851088a67b129765de662ed6f223 /lapi.c
parent1aa526263405fb4906eafab3011b13de4e5daf73 (diff)
downloadlua-34ac039fb84e3c12fb8c96c9c99c34224c09872b.tar.gz
lua-34ac039fb84e3c12fb8c96c9c99c34224c09872b.tar.bz2
lua-34ac039fb84e3c12fb8c96c9c99c34224c09872b.zip
new macro 'cvt2str' to better control whether numbers are convertible
to strings
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lapi.c b/lapi.c
index 680630dd..eb901cb3 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.230 2014/07/21 16:02:57 roberto Exp roberto $ 2** $Id: lapi.c,v 2.231 2014/07/22 18:07:47 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -279,8 +279,8 @@ LUA_API int lua_isnumber (lua_State *L, int idx) {
279 279
280 280
281LUA_API int lua_isstring (lua_State *L, int idx) { 281LUA_API int lua_isstring (lua_State *L, int idx) {
282 int t = lua_type(L, idx); 282 const TValue *o = index2addr(L, idx);
283 return (t == LUA_TSTRING || t == LUA_TNUMBER); 283 return (ttisstring(o) || cvt2str(o));
284} 284}
285 285
286 286
@@ -371,14 +371,14 @@ LUA_API int lua_toboolean (lua_State *L, int idx) {
371LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { 371LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
372 StkId o = index2addr(L, idx); 372 StkId o = index2addr(L, idx);
373 if (!ttisstring(o)) { 373 if (!ttisstring(o)) {
374 lua_lock(L); /* `luaV_tostring' may create a new string */ 374 if (!cvt2str(o)) { /* not convertible? */
375 if (!luaV_tostring(L, o)) { /* conversion failed? */
376 if (len != NULL) *len = 0; 375 if (len != NULL) *len = 0;
377 lua_unlock(L);
378 return NULL; 376 return NULL;
379 } 377 }
378 lua_lock(L); /* `luaO_tostring' may create a new string */
380 luaC_checkGC(L); 379 luaC_checkGC(L);
381 o = index2addr(L, idx); /* previous call may reallocate the stack */ 380 o = index2addr(L, idx); /* previous call may reallocate the stack */
381 luaO_tostring(L, o);
382 lua_unlock(L); 382 lua_unlock(L);
383 } 383 }
384 if (len != NULL) *len = tsvalue(o)->len; 384 if (len != NULL) *len = tsvalue(o)->len;