From 5a8f383e60543962c972f5b2c188a6aef4364c46 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 5 Jun 2002 14:42:03 -0300 Subject: [PATCH] io.close() closes standard output file; `close' now is method --- liolib.c | 10 ++++++++-- 1 file 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 @@ /* -** $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} };