aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-05-16 16:21:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-05-16 16:21:11 -0300
commitda32450c3d4c8abd3fd6709692859a12a8886511 (patch)
treea75289cd092dd6cbd9e454c9689de3b9c4d5de33 /lapi.c
parenta2b78aad49388c1fd5286773085ef8a35545faa6 (diff)
downloadlua-da32450c3d4c8abd3fd6709692859a12a8886511.tar.gz
lua-da32450c3d4c8abd3fd6709692859a12a8886511.tar.bz2
lua-da32450c3d4c8abd3fd6709692859a12a8886511.zip
new API function `lua_tolstring'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lapi.c b/lapi.c
index f6244e39..1f040b4e 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.38 2005/04/05 15:35:15 roberto Exp roberto $ 2** $Id: lapi.c,v 2.39 2005/05/05 15:34:03 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*/
@@ -334,18 +334,20 @@ LUA_API int lua_toboolean (lua_State *L, int idx) {
334} 334}
335 335
336 336
337LUA_API const char *lua_tostring (lua_State *L, int idx) { 337LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
338 StkId o = index2adr(L, idx); 338 StkId o = index2adr(L, idx);
339 if (ttisstring(o)) 339 if (!ttisstring(o)) {
340 return svalue(o);
341 else {
342 const char *s;
343 lua_lock(L); /* `luaV_tostring' may create a new string */ 340 lua_lock(L); /* `luaV_tostring' may create a new string */
344 s = (luaV_tostring(L, o) ? svalue(o) : NULL); 341 if (!luaV_tostring(L, o)) { /* conversion failed? */
342 if (len != NULL) *len = 0;
343 lua_unlock(L);
344 return NULL;
345 }
345 luaC_checkGC(L); 346 luaC_checkGC(L);
346 lua_unlock(L); 347 lua_unlock(L);
347 return s;
348 } 348 }
349 if (len != NULL) *len = tsvalue(o)->len;
350 return svalue(o);
349} 351}
350 352
351 353