aboutsummaryrefslogtreecommitdiff
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
parent6dd0b6c62bd0016f456676c335308ebdfe6ce05d (diff)
downloadlua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.tar.gz
lua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.tar.bz2
lua-a102221a0b9f5aa9347b9b15943e39e9d631e0ae.zip
better error messages
-rw-r--r--lauxlib.c11
-rw-r--r--liolib.c17
2 files changed, 20 insertions, 8 deletions
diff --git a/lauxlib.c b/lauxlib.c
index af38c670..f905361f 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.71 2002/05/16 18:39:46 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.72 2002/06/03 20:11:41 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -37,7 +37,13 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
37 lua_Debug ar; 37 lua_Debug ar;
38 lua_getstack(L, 0, &ar); 38 lua_getstack(L, 0, &ar);
39 lua_getinfo(L, "n", &ar); 39 lua_getinfo(L, "n", &ar);
40 if (strcmp(ar.namewhat, "method") == 0) narg--; /* do not count `self' */ 40 if (strcmp(ar.namewhat, "method") == 0) {
41 narg--; /* do not count `self' */
42 if (narg == 0) /* error is in the self argument itself? */
43 return luaL_verror(L,
44 "calling %s on bad self (perhaps using `:' instead of `.')",
45 ar.name);
46 }
41 if (ar.name == NULL) 47 if (ar.name == NULL)
42 ar.name = "?"; 48 ar.name = "?";
43 return luaL_verror(L, "bad argument #%d to `%s' (%s)", 49 return luaL_verror(L, "bad argument #%d to `%s' (%s)",
@@ -314,6 +320,7 @@ typedef struct LoadF {
314 320
315static const char *getF (void *ud, size_t *size) { 321static const char *getF (void *ud, size_t *size) {
316 LoadF *lf = (LoadF *)ud; 322 LoadF *lf = (LoadF *)ud;
323 if (feof(lf->f)) return NULL;
317 *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f); 324 *size = fread(lf->buff, 1, LUAL_BUFFERSIZE, lf->f);
318 return (*size > 0) ? lf->buff : NULL; 325 return (*size > 0) ? lf->buff : NULL;
319} 326}
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;