From daddc57abd31e30215922a716cb6d26422f3658b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 3 Jan 2008 15:07:59 -0200 Subject: luaL_tostring -> luaL_tolstring (more generic) --- lauxlib.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lauxlib.c') 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); } -- cgit v1.2.3-55-g6feb