aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-01 16:10:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-01 16:10:48 -0300
commitd9fbbe1f23554719ade2f870d0992e831719edc9 (patch)
tree2422a095c2e6017ca8f3c2db1c29280d14590e6f
parent4a714cebd1783fe6e5beafc2ce602df56a78723b (diff)
downloadlua-d9fbbe1f23554719ade2f870d0992e831719edc9.tar.gz
lua-d9fbbe1f23554719ade2f870d0992e831719edc9.tar.bz2
lua-d9fbbe1f23554719ade2f870d0992e831719edc9.zip
"file:write" returns "file" in case of success
-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