aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-04 16:36:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-04 16:36:42 -0300
commit6fb0b1135090b1e4543438c56ae3e444abb5477d (patch)
tree95493cdd6da2474b448f31becc4434a72e354eae /lauxlib.c
parent932e7fb0e1b35758bd96361479ca3ddab3fc43da (diff)
downloadlua-6fb0b1135090b1e4543438c56ae3e444abb5477d.tar.gz
lua-6fb0b1135090b1e4543438c56ae3e444abb5477d.tar.bz2
lua-6fb0b1135090b1e4543438c56ae3e444abb5477d.zip
string contatenation handles conversion of integers to strings +
floats always format as floats (with decimal dot or exponent)
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/lauxlib.c b/lauxlib.c
index c2620357..db46e167 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.248 2013/03/21 13:54:57 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.249 2013/04/25 13:53:13 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*/
@@ -737,15 +737,10 @@ LUALIB_API int luaL_len (lua_State *L, int idx) {
737LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { 737LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
738 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ 738 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
739 switch (lua_type(L, idx)) { 739 switch (lua_type(L, idx)) {
740 case LUA_TNUMBER: { 740 case LUA_TNUMBER: { /* concatenate with empty string to convert */
741 if (lua_isinteger(L, idx)) { 741 lua_pushvalue(L, idx);
742 lua_Integer n = lua_tointeger(L, idx); 742 lua_pushliteral(L, "");
743 lua_pushfstring(L, "%I", n); 743 lua_concat(L, 2);
744 }
745 else {
746 lua_Number n = lua_tonumber(L, idx);
747 lua_pushfstring(L, "%f", n);
748 }
749 break; 744 break;
750 } 745 }
751 case LUA_TSTRING: 746 case LUA_TSTRING: