diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-05 14:42:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-05 14:42:03 -0300 |
commit | 5a8f383e60543962c972f5b2c188a6aef4364c46 (patch) | |
tree | 4aab30aba0b8a36d19d6ed89740b81b21389ece3 | |
parent | 711b936849522446e9649858bbfe6f35b2219472 (diff) | |
download | lua-5a8f383e60543962c972f5b2c188a6aef4364c46.tar.gz lua-5a8f383e60543962c972f5b2c188a6aef4364c46.tar.bz2 lua-5a8f383e60543962c972f5b2c188a6aef4364c46.zip |
io.close() closes standard output file; `close' now is method
-rw-r--r-- | liolib.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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 | ||
100 | static int io_close (lua_State *L) { | 100 | static 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 | ||