aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-05 17:14:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-05 17:14:53 -0200
commitd438e1379d24f06f027f8fc0e8fc1ff6673b322f (patch)
treeb8ba7c184768198d6b7ade4c65968f644633baa5 /lauxlib.c
parent1721d09ac8e55bb4b675cea26cbe6b707fd21a2c (diff)
downloadlua-d438e1379d24f06f027f8fc0e8fc1ff6673b322f.tar.gz
lua-d438e1379d24f06f027f8fc0e8fc1ff6673b322f.tar.bz2
lua-d438e1379d24f06f027f8fc0e8fc1ff6673b322f.zip
insertion of ".0" in floats with integer values done by "luaL_tolstring",
not by the core
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 035cb06c..afed0fe1 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.255 2013/06/27 18:32:33 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.256 2014/01/05 14:04:46 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -746,10 +746,16 @@ LUALIB_API lua_Integer luaL_len (lua_State *L, int idx) {
746LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { 746LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
747 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ 747 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
748 switch (lua_type(L, idx)) { 748 switch (lua_type(L, idx)) {
749 case LUA_TNUMBER: { /* concatenate with empty string to convert */ 749 case LUA_TNUMBER: {
750 lua_pushvalue(L, idx); 750 if (lua_isinteger(L, idx))
751 lua_pushliteral(L, ""); 751 lua_pushfstring(L, "%I", lua_tointeger(L, idx));
752 lua_concat(L, 2); 752 else {
753 const char *s = lua_pushfstring(L, "%f", lua_tonumber(L, idx));
754 if (s[strspn(s, "-0123456789")] == '\0') { /* looks like an int? */
755 lua_pushliteral(L, ".0"); /* add a '.0' to result */
756 lua_concat(L, 2);
757 }
758 }
753 break; 759 break;
754 } 760 }
755 case LUA_TSTRING: 761 case LUA_TSTRING: