commit 9c43d6a24e2612504686f9efbade264e2246bbfb
parent 01b6fe0cbfe59fe74b255ede51806a574f5cf447
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 25 Apr 2013 10:52:48 -0300
new format "%I" in 'lua_pushfstring' for lua_Integer
Diffstat:
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git 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;
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 2.58 2013/02/20 14:08:56 roberto Exp roberto $
+** $Id: lobject.c,v 2.59 2013/04/16 18:46:28 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -219,6 +219,13 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
setnvalue(L->top++, cast_num(va_arg(argp, int)));
break;
}
+ case 'I': {
+ char buff[LUA_MAXINTEGER2STR];
+ lua_Integer i = cast(lua_Integer, va_arg(argp, lua_Integer));
+ int l = lua_integer2str(buff, i);
+ pushstr(L, buff, l);
+ break;
+ }
case 'f': {
setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
break;