diff options
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 17 |
1 files changed, 11 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.4 2002/05/02 17:12:27 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.5 2002/05/06 19:05:10 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 | */ |
| @@ -60,8 +60,9 @@ static FILE *tofile (lua_State *L, int findex) { | |||
| 60 | lua_pop(L, 1); | 60 | lua_pop(L, 1); |
| 61 | return *f; | 61 | return *f; |
| 62 | } | 62 | } |
| 63 | luaL_argerror(L, findex, "bad file"); | 63 | if (findex > 0) |
| 64 | return NULL; /* to avoid warnings */ | 64 | luaL_argerror(L, findex, "bad file"); |
| 65 | return NULL; | ||
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | 68 | ||
| @@ -133,14 +134,18 @@ static int io_tmpfile (lua_State *L) { | |||
| 133 | 134 | ||
| 134 | 135 | ||
| 135 | static FILE *getiofile (lua_State *L, const char *name) { | 136 | static FILE *getiofile (lua_State *L, const char *name) { |
| 137 | FILE *f; | ||
| 136 | lua_pushstring(L, name); | 138 | lua_pushstring(L, name); |
| 137 | lua_rawget(L, lua_upvalueindex(1)); | 139 | lua_rawget(L, lua_upvalueindex(1)); |
| 138 | return tofile(L, -1); | 140 | f = tofile(L, -1); |
| 141 | if (f == NULL) | ||
| 142 | luaL_verror(L, "%s is closed", name); | ||
| 143 | return f; | ||
| 139 | } | 144 | } |
| 140 | 145 | ||
| 141 | 146 | ||
| 142 | static int g_iofile (lua_State *L, const char *name, const char *mode) { | 147 | static int g_iofile (lua_State *L, const char *name, const char *mode) { |
| 143 | if (lua_isnone(L, 1)) { | 148 | if (lua_isnoneornil(L, 1)) { |
| 144 | lua_pushstring(L, name); | 149 | lua_pushstring(L, name); |
| 145 | lua_rawget(L, lua_upvalueindex(1)); | 150 | lua_rawget(L, lua_upvalueindex(1)); |
| 146 | return 1; | 151 | return 1; |
| @@ -154,8 +159,8 @@ static int g_iofile (lua_State *L, const char *name, const char *mode) { | |||
| 154 | newfile(L, f); | 159 | newfile(L, f); |
| 155 | } | 160 | } |
| 156 | else { | 161 | else { |
| 162 | tofile(L, 1); /* check that it's a valid file handle */ | ||
| 157 | lua_pushvalue(L, 1); | 163 | lua_pushvalue(L, 1); |
| 158 | tofile(L, -1); /* check that it's a valid file handle */ | ||
| 159 | } | 164 | } |
| 160 | lua_rawset(L, lua_upvalueindex(1)); | 165 | lua_rawset(L, lua_upvalueindex(1)); |
| 161 | return 0; | 166 | return 0; |
