diff options
-rw-r--r-- | lauxlib.c | 11 | ||||
-rw-r--r-- | lobject.c | 5 | ||||
-rw-r--r-- | lvm.c | 15 |
3 files changed, 18 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.261 2014/04/01 18:55:06 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.262 2014/04/15 18:25:49 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 | */ |
@@ -757,13 +757,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
757 | case LUA_TNUMBER: { | 757 | case LUA_TNUMBER: { |
758 | if (lua_isinteger(L, idx)) | 758 | if (lua_isinteger(L, idx)) |
759 | lua_pushfstring(L, "%I", lua_tointeger(L, idx)); | 759 | lua_pushfstring(L, "%I", lua_tointeger(L, idx)); |
760 | else { | 760 | else |
761 | const char *s = lua_pushfstring(L, "%f", lua_tonumber(L, idx)); | 761 | lua_pushfstring(L, "%f", lua_tonumber(L, idx)); |
762 | if (s[strspn(s, "-0123456789")] == '\0') { /* looks like an int? */ | ||
763 | lua_pushliteral(L, ".0"); /* add a '.0' to result */ | ||
764 | lua_concat(L, 2); | ||
765 | } | ||
766 | } | ||
767 | break; | 762 | break; |
768 | } | 763 | } |
769 | case LUA_TSTRING: | 764 | case LUA_TSTRING: |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.84 2014/05/01 18:18:06 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.85 2014/05/12 21:22:05 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -356,14 +356,17 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
356 | } | 356 | } |
357 | case 'd': { | 357 | case 'd': { |
358 | setivalue(L->top++, cast_int(va_arg(argp, int))); | 358 | setivalue(L->top++, cast_int(va_arg(argp, int))); |
359 | luaV_tostring(L, L->top - 1); | ||
359 | break; | 360 | break; |
360 | } | 361 | } |
361 | case 'I': { | 362 | case 'I': { |
362 | setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt))); | 363 | setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt))); |
364 | luaV_tostring(L, L->top - 1); | ||
363 | break; | 365 | break; |
364 | } | 366 | } |
365 | case 'f': { | 367 | case 'f': { |
366 | setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); | 368 | setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); |
369 | luaV_tostring(L, L->top - 1); | ||
367 | break; | 370 | break; |
368 | } | 371 | } |
369 | case 'p': { | 372 | case 'p': { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.207 2014/05/12 19:13:32 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.208 2014/05/12 21:22:05 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -135,9 +135,16 @@ int luaV_tostring (lua_State *L, StkId obj) { | |||
135 | return 0; | 135 | return 0; |
136 | else { | 136 | else { |
137 | char buff[MAXNUMBER2STR]; | 137 | char buff[MAXNUMBER2STR]; |
138 | size_t len = (ttisinteger(obj)) | 138 | size_t len; |
139 | ? lua_integer2str(buff, ivalue(obj)) | 139 | if (ttisinteger(obj)) |
140 | : lua_number2str(buff, fltvalue(obj)); | 140 | len = lua_integer2str(buff, ivalue(obj)); |
141 | else { | ||
142 | len = lua_number2str(buff, fltvalue(obj)); | ||
143 | if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */ | ||
144 | buff[len++] = '.'; | ||
145 | buff[len++] = '0'; /* adds '.0' to result */ | ||
146 | } | ||
147 | } | ||
141 | setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); | 148 | setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); |
142 | return 1; | 149 | return 1; |
143 | } | 150 | } |