commit 5a8f383e60543962c972f5b2c188a6aef4364c46
parent 711b936849522446e9649858bbfe6f35b2219472
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 5 Jun 2002 14:41:41 -0300
io.close() closes standard output file; `close' now is method
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/liolib.c b/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
** 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) {
- 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;
if (f != stdin && f != stdout && f != stderr) {
lua_settop(L, 1); /* make sure file is on top */
@@ -379,6 +384,7 @@ static const luaL_reg flib[] = {
{"read", f_read},
{"seek", f_seek},
{"write", f_write},
+ {"close", io_close},
{NULL, NULL}
};