From 45c430eac04b070a996437b79e40656942a4c7d4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 12 May 2014 18:44:17 -0300 Subject: [PATCH] addition of '.0' to float representation done by the kernel --- lauxlib.c | 11 +++-------- lobject.c | 5 ++++- lvm.c | 15 +++++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index 843843ce..06a5882d 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.261 2014/04/01 18:55:06 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.262 2014/04/15 18:25:49 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -757,13 +757,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { case LUA_TNUMBER: { if (lua_isinteger(L, idx)) lua_pushfstring(L, "%I", lua_tointeger(L, idx)); - else { - const char *s = lua_pushfstring(L, "%f", lua_tonumber(L, idx)); - if (s[strspn(s, "-0123456789")] == '\0') { /* looks like an int? */ - lua_pushliteral(L, ".0"); /* add a '.0' to result */ - lua_concat(L, 2); - } - } + else + lua_pushfstring(L, "%f", lua_tonumber(L, idx)); break; } case LUA_TSTRING: diff --git a/lobject.c b/lobject.c index 025f94b0..93acc9ae 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.84 2014/05/01 18:18:06 roberto Exp roberto $ +** $Id: lobject.c,v 2.85 2014/05/12 21:22:05 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -356,14 +356,17 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { } case 'd': { setivalue(L->top++, cast_int(va_arg(argp, int))); + luaV_tostring(L, L->top - 1); break; } case 'I': { setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt))); + luaV_tostring(L, L->top - 1); break; } case 'f': { setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); + luaV_tostring(L, L->top - 1); break; } case 'p': { diff --git a/lvm.c b/lvm.c index 3fb8f12e..4f5d8fe1 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.207 2014/05/12 19:13:32 roberto Exp roberto $ +** $Id: lvm.c,v 2.208 2014/05/12 21:22:05 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -135,9 +135,16 @@ int luaV_tostring (lua_State *L, StkId obj) { return 0; else { char buff[MAXNUMBER2STR]; - size_t len = (ttisinteger(obj)) - ? lua_integer2str(buff, ivalue(obj)) - : lua_number2str(buff, fltvalue(obj)); + size_t len; + if (ttisinteger(obj)) + len = lua_integer2str(buff, ivalue(obj)); + else { + len = lua_number2str(buff, fltvalue(obj)); + if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */ + buff[len++] = '.'; + buff[len++] = '0'; /* adds '.0' to result */ + } + } setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); return 1; }