diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-02-09 12:50:05 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-02-09 12:50:05 -0200 |
commit | d266d40deaaf0fc7234a06217e121a158c980085 (patch) | |
tree | 3e84bb0af9e24f19573090515b280abf29842d2a /liolib.c | |
parent | e354c6355e7f48e087678ec49e340ca0696725b1 (diff) | |
download | lua-d266d40deaaf0fc7234a06217e121a158c980085.tar.gz lua-d266d40deaaf0fc7234a06217e121a158c980085.tar.bz2 lua-d266d40deaaf0fc7234a06217e121a158c980085.zip |
error when calling close method without arguments (e.g.,
|io.stdin.close()|)
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.150 2016/09/01 16:14:56 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 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 | */ |
@@ -206,11 +206,16 @@ static int aux_close (lua_State *L) { | |||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | static int f_close (lua_State *L) { | ||
210 | tofile(L); /* make sure argument is an open stream */ | ||
211 | return aux_close(L); | ||
212 | } | ||
213 | |||
214 | |||
209 | static int io_close (lua_State *L) { | 215 | static int io_close (lua_State *L) { |
210 | if (lua_isnone(L, 1)) /* no argument? */ | 216 | if (lua_isnone(L, 1)) /* no argument? */ |
211 | lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ | 217 | lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ |
212 | tofile(L); /* make sure argument is an open stream */ | 218 | return f_close(L); |
213 | return aux_close(L); | ||
214 | } | 219 | } |
215 | 220 | ||
216 | 221 | ||
@@ -712,7 +717,7 @@ static const luaL_Reg iolib[] = { | |||
712 | ** methods for file handles | 717 | ** methods for file handles |
713 | */ | 718 | */ |
714 | static const luaL_Reg flib[] = { | 719 | static const luaL_Reg flib[] = { |
715 | {"close", io_close}, | 720 | {"close", f_close}, |
716 | {"flush", f_flush}, | 721 | {"flush", f_flush}, |
717 | {"lines", f_lines}, | 722 | {"lines", f_lines}, |
718 | {"read", f_read}, | 723 | {"read", f_read}, |