From daddc57abd31e30215922a716cb6d26422f3658b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 3 Jan 2008 15:07:59 -0200 Subject: [PATCH] luaL_tostring -> luaL_tolstring (more generic) --- lauxlib.c | 17 +++++++++++------ lauxlib.h | 4 ++-- lbaselib.c | 4 ++-- 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 @@ /* -** $Id: lauxlib.c,v 1.173 2007/09/05 17:17:39 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.174 2007/09/14 13:26:28 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -550,23 +550,28 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { } -LUALIB_API const char *luaL_tostring (lua_State *L, int idx) { +LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ switch (lua_type(L, idx)) { case LUA_TNUMBER: - return lua_pushstring(L, lua_tostring(L, idx)); + lua_pushstring(L, lua_tostring(L, idx)); + break; case LUA_TSTRING: lua_pushvalue(L, idx); break; case LUA_TBOOLEAN: - return lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); + lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); + break; case LUA_TNIL: - return lua_pushliteral(L, "nil"); + lua_pushliteral(L, "nil"); + break; default: - return lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), + lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), lua_topointer(L, idx)); + break; } } + if (len) *len = lua_objlen(L, -1); return lua_tostring(L, -1); } diff --git a/lauxlib.h b/lauxlib.h index e0850c60..34172b9a 100644 --- a/lauxlib.h +++ b/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.92 2007/06/22 15:33:54 roberto Exp roberto $ +** $Id: lauxlib.h,v 1.93 2007/06/22 15:39:34 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -33,7 +33,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); -LUALIB_API const char *luaL_tostring (lua_State *L, int idx); +LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); LUALIB_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 @@ /* -** $Id: lbaselib.c,v 1.200 2007/10/25 19:31:05 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.201 2007/11/28 18:25:17 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -405,7 +405,7 @@ static int luaB_xpcall (lua_State *L) { static int luaB_tostring (lua_State *L) { luaL_checkany(L, 1); - luaL_tostring(L, 1); + luaL_tolstring(L, 1, NULL); return 1; }