better error messages

This commit is contained in:
Roberto Ierusalimschy 2003-03-19 18:16:12 -03:00
parent 0ca225d33a
commit 1a553f9199
2 changed files with 7 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 2.37 2003/03/14 19:08:11 roberto Exp roberto $ ** $Id: liolib.c,v 2.38 2003/03/18 12:25:32 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -377,8 +377,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
} }
else { else {
const char *p = lua_tostring(L, n); const char *p = lua_tostring(L, n);
if (!p || p[0] != '*') luaL_argcheck(L, p && p[0] == '*', n, "invalid option");
return luaL_error(L, "invalid `read' option");
switch (p[1]) { switch (p[1]) {
case 'n': /* number */ case 'n': /* number */
success = read_number(L, f); success = read_number(L, f);
@ -391,7 +390,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
success = 1; /* always success */ success = 1; /* always success */
break; break;
case 'w': /* word */ case 'w': /* word */
return luaL_error(L, "obsolete option `*w'"); return luaL_error(L, "obsolete option `*w' to `read'");
default: default:
return luaL_argerror(L, n, "invalid format"); return luaL_argerror(L, n, "invalid format");
} }
@ -563,7 +562,7 @@ static int io_tmpname (lua_State *L) {
#else #else
char buff[L_tmpnam]; char buff[L_tmpnam];
if (tmpnam(buff) != buff) if (tmpnam(buff) != buff)
return luaL_error(L, "unable to generate a unique filename"); return luaL_error(L, "unable to generate a unique filename in `tmpname'");
lua_pushstring(L, buff); lua_pushstring(L, buff);
return 1; return 1;
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.95 2003/03/11 12:24:34 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.96 2003/03/14 18:59:53 roberto Exp roberto $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -695,7 +695,7 @@ static int str_format (lua_State *L) {
char buff[MAX_ITEM]; /* to store the formatted item */ char buff[MAX_ITEM]; /* to store the formatted item */
int hasprecision = 0; int hasprecision = 0;
if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$')
return luaL_error(L, "obsolete `format' option (d$)"); return luaL_error(L, "obsolete option (d$) to `format'");
arg++; arg++;
strfrmt = scanformat(L, strfrmt, form, &hasprecision); strfrmt = scanformat(L, strfrmt, form, &hasprecision);
switch (*strfrmt++) { switch (*strfrmt++) {
@ -732,7 +732,7 @@ static int str_format (lua_State *L) {
} }
} }
default: { /* also treat cases `pnLlh' */ default: { /* also treat cases `pnLlh' */
return luaL_error(L, "invalid option in `format'"); return luaL_error(L, "invalid option to `format'");
} }
} }
luaL_addlstring(&b, buff, strlen(buff)); luaL_addlstring(&b, buff, strlen(buff));