aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-05 13:59:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-05 13:59:37 -0300
commita102221a0b9f5aa9347b9b15943e39e9d631e0ae (patch)
treebdd1431942fbb7d337c7f2d6452faeb795511ea5 /liolib.c
parent6dd0b6c62bd0016f456676c335308ebdfe6ce05d (diff)
downloadlua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.tar.gz
lua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.tar.bz2
lua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.zip
better error messages
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/liolib.c b/liolib.c
index 6d6024cf..5ed8fae2 100644
--- a/liolib.c
+++ b/liolib.c
@@ -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
135static FILE *getiofile (lua_State *L, const char *name) { 136static 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
142static int g_iofile (lua_State *L, const char *name, const char *mode) { 147static 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;