From 6fb0b1135090b1e4543438c56ae3e444abb5477d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 4 Jun 2013 16:36:42 -0300 Subject: string contatenation handles conversion of integers to strings + floats always format as floats (with decimal dot or exponent) --- lauxlib.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index c2620357..db46e167 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.248 2013/03/21 13:54:57 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.249 2013/04/25 13:53:13 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -737,15 +737,10 @@ LUALIB_API int luaL_len (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: { - if (lua_isinteger(L, idx)) { - lua_Integer n = lua_tointeger(L, idx); - lua_pushfstring(L, "%I", n); - } - else { - lua_Number n = lua_tonumber(L, idx); - lua_pushfstring(L, "%f", n); - } + case LUA_TNUMBER: { /* concatenate with empty string to convert */ + lua_pushvalue(L, idx); + lua_pushliteral(L, ""); + lua_concat(L, 2); break; } case LUA_TSTRING: -- cgit v1.2.3-55-g6feb