Browse Source

better treatment of integer formats in string.format

pull/9/head
Roberto Ierusalimschy 16 years ago
parent
commit
f4eed60ca9
  1. 13
      lstrlib.c

13
lstrlib.c

@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.141 2008/06/12 14:21:18 roberto Exp roberto $
** $Id: lstrlib.c,v 1.142 2009/02/03 19:39:19 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@ -777,14 +777,13 @@ static int str_format (lua_State *L) {
sprintf(buff, form, (int)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i': {
addintlen(form);
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i':
case 'o': case 'u': case 'x': case 'X': {
lua_Number n = luaL_checknumber(L, arg);
LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n :
(LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n;
addintlen(form);
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
sprintf(buff, form, r);
break;
}
case 'e': case 'E': case 'f':

Loading…
Cancel
Save