aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/liolib.c b/liolib.c
index 8a543a81..7427806c 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.80 2009/02/20 13:50:27 roberto Exp roberto $ 2** $Id: liolib.c,v 2.81 2009/08/28 13:51:57 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*/
@@ -422,7 +422,7 @@ static int io_readline (lua_State *L) {
422 422
423 423
424static int g_write (lua_State *L, FILE *f, int arg) { 424static int g_write (lua_State *L, FILE *f, int arg) {
425 int nargs = lua_gettop(L) - 1; 425 int nargs = lua_gettop(L) - arg;
426 int status = 1; 426 int status = 1;
427 for (; nargs--; arg++) { 427 for (; nargs--; arg++) {
428 if (lua_type(L, arg) == LUA_TNUMBER) { 428 if (lua_type(L, arg) == LUA_TNUMBER) {
@@ -436,7 +436,8 @@ static int g_write (lua_State *L, FILE *f, int arg) {
436 status = status && (fwrite(s, sizeof(char), l, f) == l); 436 status = status && (fwrite(s, sizeof(char), l, f) == l);
437 } 437 }
438 } 438 }
439 return pushresult(L, status, NULL); 439 if (status) return 1; /* file handle already on stack top */
440 else return pushresult(L, status, NULL);
440} 441}
441 442
442 443
@@ -446,7 +447,9 @@ static int io_write (lua_State *L) {
446 447
447 448
448static int f_write (lua_State *L) { 449static int f_write (lua_State *L) {
449 return g_write(L, tofile(L), 2); 450 FILE * f = tofile(L);
451 lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
452 return g_write(L, f, 2);
450} 453}
451 454
452 455