aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-14 16:08:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-14 16:08:11 -0300
commit7ea180af6eea4d3ab0a9afe03836e53e0b3e5cde (patch)
tree21741a84445bdc08cdca0d6ff4ed08c61d7b9c67
parent05d567d52e9155327b73fab14d7d635726943d94 (diff)
downloadlua-7ea180af6eea4d3ab0a9afe03836e53e0b3e5cde.tar.gz
lua-7ea180af6eea4d3ab0a9afe03836e53e0b3e5cde.tar.bz2
lua-7ea180af6eea4d3ab0a9afe03836e53e0b3e5cde.zip
detail
-rw-r--r--liolib.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/liolib.c b/liolib.c
index b18a12e4..b4b8c9b9 100644
--- a/liolib.c
+++ b/liolib.c
@@ -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
233static int g_iofile (lua_State *L, const char *name, const char *mode) { 233static 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