Browse Source

io.close() closes standard output file; `close' now is method

Roberto Ierusalimschy 23 years ago
parent
commit
5a8f383e60
1 changed files with 8 additions and 2 deletions
  1. 8 2
      liolib.c

+ 8 - 2
liolib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: liolib.c,v 2.6 2002/06/05 16:59:37 roberto Exp roberto $
+** $Id: liolib.c,v 2.7 2002/06/05 17:24:04 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -98,7 +98,12 @@ static int setnewfile (lua_State *L, FILE *f) {
 
 
 
 
 static int io_close (lua_State *L) {
 static int io_close (lua_State *L) {
-  FILE *f = tofile(L, 1);
+  FILE *f;
+  if (lua_isnone(L, 1)) {
+    lua_pushstring(L, IO_OUTPUT);
+    lua_rawget(L, lua_upvalueindex(1));
+  }
+  f = tofile(L, 1);
   int status = 1;
   int status = 1;
   if (f != stdin && f != stdout && f != stderr) {
   if (f != stdin && f != stdout && f != stderr) {
     lua_settop(L, 1);  /* make sure file is on top */
     lua_settop(L, 1);  /* make sure file is on top */
@@ -379,6 +384,7 @@ static const luaL_reg flib[] = {
   {"read", f_read},
   {"read", f_read},
   {"seek", f_seek},
   {"seek", f_seek},
   {"write", f_write},
   {"write", f_write},
+  {"close", io_close},
   {NULL, NULL}
   {NULL, NULL}
 };
 };