aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
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