aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-03 15:07:59 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-03 15:07:59 -0200
commitdaddc57abd31e30215922a716cb6d26422f3658b (patch)
tree9b1a5d628c40d5551595d9349e09e7aba56a88fc
parentf9cdd09191e01ef38da674ef66af408d7e309d9f (diff)
downloadlua-daddc57abd31e30215922a716cb6d26422f3658b.tar.gz
lua-daddc57abd31e30215922a716cb6d26422f3658b.tar.bz2
lua-daddc57abd31e30215922a716cb6d26422f3658b.zip
luaL_tostring -> luaL_tolstring (more generic)
-rw-r--r--lauxlib.c17
-rw-r--r--lauxlib.h4
-rw-r--r--lbaselib.c4
3 files changed, 15 insertions, 10 deletions
diff --git a/lauxlib.c b/lauxlib.c
index e9f738b5..91a62dc8 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.173 2007/09/05 17:17:39 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.174 2007/09/14 13:26:28 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -550,23 +550,28 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
550} 550}
551 551
552 552
553LUALIB_API const char *luaL_tostring (lua_State *L, int idx) { 553LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
554 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ 554 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
555 switch (lua_type(L, idx)) { 555 switch (lua_type(L, idx)) {
556 case LUA_TNUMBER: 556 case LUA_TNUMBER:
557 return lua_pushstring(L, lua_tostring(L, idx)); 557 lua_pushstring(L, lua_tostring(L, idx));
558 break;
558 case LUA_TSTRING: 559 case LUA_TSTRING:
559 lua_pushvalue(L, idx); 560 lua_pushvalue(L, idx);
560 break; 561 break;
561 case LUA_TBOOLEAN: 562 case LUA_TBOOLEAN:
562 return lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); 563 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
564 break;
563 case LUA_TNIL: 565 case LUA_TNIL:
564 return lua_pushliteral(L, "nil"); 566 lua_pushliteral(L, "nil");
567 break;
565 default: 568 default:
566 return lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), 569 lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
567 lua_topointer(L, idx)); 570 lua_topointer(L, idx));
571 break;
568 } 572 }
569 } 573 }
574 if (len) *len = lua_objlen(L, -1);
570 return lua_tostring(L, -1); 575 return lua_tostring(L, -1);
571} 576}
572 577
diff --git a/lauxlib.h b/lauxlib.h
index e0850c60..34172b9a 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.92 2007/06/22 15:33:54 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.93 2007/06/22 15:39:34 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -33,7 +33,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
33 const luaL_Reg *l); 33 const luaL_Reg *l);
34LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 34LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
35LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 35LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
36LUALIB_API const char *luaL_tostring (lua_State *L, int idx); 36LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len);
37LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 37LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
38LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 38LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
39LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 39LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
diff --git a/lbaselib.c b/lbaselib.c
index 32fc8cb8..f494f8be 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.200 2007/10/25 19:31:05 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.201 2007/11/28 18:25:17 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -405,7 +405,7 @@ static int luaB_xpcall (lua_State *L) {
405 405
406static int luaB_tostring (lua_State *L) { 406static int luaB_tostring (lua_State *L) {
407 luaL_checkany(L, 1); 407 luaL_checkany(L, 1);
408 luaL_tostring(L, 1); 408 luaL_tolstring(L, 1, NULL);
409 return 1; 409 return 1;
410} 410}
411 411