diff options
| -rw-r--r-- | liolib.c | 17 |
1 files changed, 7 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.35 2003/03/11 12:24:34 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.36 2003/03/14 19:00:16 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 | */ |
| @@ -231,13 +231,9 @@ static FILE *getiofile (lua_State *L, const char *name) { | |||
| 231 | 231 | ||
| 232 | 232 | ||
| 233 | static int g_iofile (lua_State *L, const char *name, const char *mode) { | 233 | static int g_iofile (lua_State *L, const char *name, const char *mode) { |
| 234 | if (lua_isnoneornil(L, 1)) { | 234 | if (!lua_isnoneornil(L, 1)) { |
| 235 | lua_pushstring(L, name); | ||
| 236 | lua_rawget(L, lua_upvalueindex(1)); | ||
| 237 | return 1; | ||
| 238 | } | ||
| 239 | else { | ||
| 240 | const char *filename = lua_tostring(L, 1); | 235 | const char *filename = lua_tostring(L, 1); |
| 236 | lua_pushstring(L, name); | ||
| 241 | if (filename) { | 237 | if (filename) { |
| 242 | FILE **pf = newfile(L); | 238 | FILE **pf = newfile(L); |
| 243 | *pf = fopen(filename, mode); | 239 | *pf = fopen(filename, mode); |
| @@ -250,11 +246,12 @@ static int g_iofile (lua_State *L, const char *name, const char *mode) { | |||
| 250 | tofile(L, 1); /* check that it's a valid file handle */ | 246 | tofile(L, 1); /* check that it's a valid file handle */ |
| 251 | lua_pushvalue(L, 1); | 247 | lua_pushvalue(L, 1); |
| 252 | } | 248 | } |
| 253 | lua_pushstring(L, name); | ||
| 254 | lua_pushvalue(L, -2); | ||
| 255 | lua_rawset(L, lua_upvalueindex(1)); | 249 | lua_rawset(L, lua_upvalueindex(1)); |
| 256 | return 1; | ||
| 257 | } | 250 | } |
| 251 | /* return current value */ | ||
| 252 | lua_pushstring(L, name); | ||
| 253 | lua_rawget(L, lua_upvalueindex(1)); | ||
| 254 | return 1; | ||
| 258 | } | 255 | } |
| 259 | 256 | ||
| 260 | 257 | ||
