From 9c43d6a24e2612504686f9efbade264e2246bbfb Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 25 Apr 2013 10:53:13 -0300 Subject: new format "%I" in 'lua_pushfstring' for lua_Integer --- lauxlib.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index 286e0430..c2620357 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.247 2012/10/19 15:55:01 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.248 2013/03/21 13:54:57 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -737,7 +737,17 @@ LUALIB_API int luaL_len (lua_State *L, int idx) { LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ switch (lua_type(L, idx)) { - case LUA_TNUMBER: + case LUA_TNUMBER: { + if (lua_isinteger(L, idx)) { + lua_Integer n = lua_tointeger(L, idx); + lua_pushfstring(L, "%I", n); + } + else { + lua_Number n = lua_tonumber(L, idx); + lua_pushfstring(L, "%f", n); + } + break; + } case LUA_TSTRING: lua_pushvalue(L, idx); break; -- cgit v1.2.3-55-g6feb