addition of '.0' to float representation done by the kernel

This commit is contained in:
Roberto Ierusalimschy
2014-05-12 18:44:17 -03:00
parent 27d9219cf3
commit 45c430eac0
3 changed files with 18 additions and 13 deletions

View File

@@ -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: