diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-07 16:01:35 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-07 16:01:35 -0300 |
commit | 48adb6984c9af1deb32deda0430f092973ec8d6a (patch) | |
tree | ebe86f1c2577b36f706be01229fb91c5f77e2fca | |
parent | c5069528e1da3d4651f167011404bcf388ba1c71 (diff) | |
download | lua-48adb6984c9af1deb32deda0430f092973ec8d6a.tar.gz lua-48adb6984c9af1deb32deda0430f092973ec8d6a.tar.bz2 lua-48adb6984c9af1deb32deda0430f092973ec8d6a.zip |
'io.write' writes integers directly (and correctly)
-rw-r--r-- | liolib.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.112 2013/04/11 18:34:06 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.113 2013/05/14 15:57:43 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -533,8 +533,10 @@ static int g_write (lua_State *L, FILE *f, int arg) { | |||
533 | for (; nargs--; arg++) { | 533 | for (; nargs--; arg++) { |
534 | if (lua_type(L, arg) == LUA_TNUMBER) { | 534 | if (lua_type(L, arg) == LUA_TNUMBER) { |
535 | /* optimization: could be done exactly as for strings */ | 535 | /* optimization: could be done exactly as for strings */ |
536 | status = status && | 536 | int len = lua_isinteger(L, arg) |
537 | fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; | 537 | ? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg)) |
538 | : fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)); | ||
539 | status = status && (len > 0); | ||
538 | } | 540 | } |
539 | else { | 541 | else { |
540 | size_t l; | 542 | size_t l; |