aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-05 14:42:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-05 14:42:03 -0300
commit5a8f383e60543962c972f5b2c188a6aef4364c46 (patch)
tree4aab30aba0b8a36d19d6ed89740b81b21389ece3
parent711b936849522446e9649858bbfe6f35b2219472 (diff)
downloadlua-5a8f383e60543962c972f5b2c188a6aef4364c46.tar.gz
lua-5a8f383e60543962c972f5b2c188a6aef4364c46.tar.bz2
lua-5a8f383e60543962c972f5b2c188a6aef4364c46.zip
io.close() closes standard output file; `close' now is method
-rw-r--r--liolib.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/liolib.c b/liolib.c
index e43d2261..f2445b71 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.6 2002/06/05 16:59:37 roberto Exp roberto $ 2** $Id: liolib.c,v 2.7 2002/06/05 17:24:04 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*/
@@ -98,7 +98,12 @@ static int setnewfile (lua_State *L, FILE *f) {
98 98
99 99
100static int io_close (lua_State *L) { 100static int io_close (lua_State *L) {
101 FILE *f = tofile(L, 1); 101 FILE *f;
102 if (lua_isnone(L, 1)) {
103 lua_pushstring(L, IO_OUTPUT);
104 lua_rawget(L, lua_upvalueindex(1));
105 }
106 f = tofile(L, 1);
102 int status = 1; 107 int status = 1;
103 if (f != stdin && f != stdout && f != stderr) { 108 if (f != stdin && f != stdout && f != stderr) {
104 lua_settop(L, 1); /* make sure file is on top */ 109 lua_settop(L, 1); /* make sure file is on top */
@@ -379,6 +384,7 @@ static const luaL_reg flib[] = {
379 {"read", f_read}, 384 {"read", f_read},
380 {"seek", f_seek}, 385 {"seek", f_seek},
381 {"write", f_write}, 386 {"write", f_write},
387 {"close", io_close},
382 {NULL, NULL} 388 {NULL, NULL}
383}; 389};
384 390