all textual errors go through `luaL_verror'

This commit is contained in:
Roberto Ierusalimschy
2002-05-02 14:12:27 -03:00
parent 3c6a383d62
commit 85dcb411a8
5 changed files with 28 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.69 2002/04/22 14:40:23 roberto Exp roberto $ ** $Id: lbaselib.c,v 1.70 2002/05/01 20:40:42 roberto Exp roberto $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -72,7 +72,7 @@ static int luaB_print (lua_State *L) {
lua_rawcall(L, 1, 1); lua_rawcall(L, 1, 1);
s = lua_tostring(L, -1); /* get result */ s = lua_tostring(L, -1); /* get result */
if (s == NULL) if (s == NULL)
lua_error(L, "`tostring' must return a string to `print'"); luaL_verror(L, "`tostring' must return a string to `print'");
if (i>1) fputs("\t", stdout); if (i>1) fputs("\t", stdout);
fputs(s, stdout); fputs(s, stdout);
lua_pop(L, 1); /* pop result */ lua_pop(L, 1); /* pop result */
@@ -372,7 +372,7 @@ static int luaB_require (lua_State *L) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
lua_setglobal(L, "_REQUIREDNAME"); lua_setglobal(L, "_REQUIREDNAME");
lua_getglobal(L, REQTAB); lua_getglobal(L, REQTAB);
if (!lua_istable(L, 2)) lua_error(L, REQTAB " is not a table"); if (!lua_istable(L, 2)) luaL_verror(L, REQTAB " is not a table");
path = getpath(L); path = getpath(L);
lua_pushvalue(L, 1); /* check package's name in book-keeping table */ lua_pushvalue(L, 1); /* check package's name in book-keeping table */
lua_gettable(L, 2); lua_gettable(L, 2);
@@ -399,7 +399,7 @@ static int luaB_require (lua_State *L) {
lua_tostring(L, 1), lua_tostring(L, 3)); lua_tostring(L, 1), lua_tostring(L, 3));
} }
default: { default: {
lua_error(L, "error loading package"); luaL_verror(L, "error loading package");
return 0; /* to avoid warnings */ return 0; /* to avoid warnings */
} }
} }
@@ -466,7 +466,7 @@ static int luaB_coroutine (lua_State *L) {
luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1, luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
"Lua function expected"); "Lua function expected");
NL = lua_newthread(L); NL = lua_newthread(L);
if (NL == NULL) lua_error(L, "unable to create new thread"); if (NL == NULL) luaL_verror(L, "unable to create new thread");
/* move function and arguments from L to NL */ /* move function and arguments from L to NL */
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
ref = lua_ref(L, 1); ref = lua_ref(L, 1);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 2.2 2002/04/05 18:54:31 roberto Exp roberto $ ** $Id: liolib.c,v 2.3 2002/04/12 19:56:25 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
*/ */
@@ -118,7 +118,7 @@ static int io_open (lua_State *L) {
static int io_popen (lua_State *L) { static int io_popen (lua_State *L) {
#ifndef POPEN #ifndef POPEN
lua_error(L, "`popen' not supported"); luaL_verror(L, "`popen' not supported");
return 0; return 0;
#else #else
FILE *f = popen(luaL_check_string(L, 1), luaL_opt_string(L, 2, "r")); FILE *f = popen(luaL_check_string(L, 1), luaL_opt_string(L, 2, "r"));
@@ -257,7 +257,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] != '*') if (!p || p[0] != '*')
lua_error(L, "invalid `read' option"); luaL_verror(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);
@@ -270,7 +270,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 */
lua_error(L, "obsolete option `*w'"); luaL_verror(L, "obsolete option `*w'");
break; break;
default: default:
luaL_argerror(L, n, "invalid format"); luaL_argerror(L, n, "invalid format");
@@ -430,7 +430,7 @@ static int io_rename (lua_State *L) {
static int io_tmpname (lua_State *L) { static int io_tmpname (lua_State *L) {
char buff[L_tmpnam]; char buff[L_tmpnam];
if (tmpnam(buff) != buff) if (tmpnam(buff) != buff)
lua_error(L, "unable to generate a unique filename"); luaL_verror(L, "unable to generate a unique filename");
lua_pushstring(L, buff); lua_pushstring(L, buff);
return 1; return 1;
} }
@@ -510,7 +510,7 @@ static int io_date (lua_State *L) {
if (strftime(b, sizeof(b), s, stm)) if (strftime(b, sizeof(b), s, stm))
lua_pushstring(L, b); lua_pushstring(L, b);
else else
lua_error(L, "invalid `date' format"); luaL_verror(L, "invalid `date' format");
} }
return 1; return 1;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.42 2002/04/02 20:41:59 roberto Exp roberto $ ** $Id: lmathlib.c,v 1.43 2002/04/04 20:20:49 roberto Exp roberto $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -187,7 +187,7 @@ static int math_random (lua_State *L) {
lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */ lua_pushnumber(L, (int)(r*(u-l+1))+l); /* integer between `l' and `u' */
break; break;
} }
default: lua_error(L, "wrong number of arguments"); default: luaL_verror(L, "wrong number of arguments");
} }
return 1; return 1;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.79 2002/03/20 12:54:08 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.80 2002/04/02 20:41:59 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
*/ */
@@ -170,7 +170,7 @@ typedef struct MatchState {
static int check_capture (MatchState *ms, int l) { static int check_capture (MatchState *ms, int l) {
l -= '1'; l -= '1';
if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
lua_error(ms->L, "invalid capture index"); luaL_verror(ms->L, "invalid capture index");
return l; return l;
} }
@@ -179,7 +179,7 @@ static int capture_to_close (MatchState *ms) {
int level = ms->level; int level = ms->level;
for (level--; level>=0; level--) for (level--; level>=0; level--)
if (ms->capture[level].len == CAP_UNFINISHED) return level; if (ms->capture[level].len == CAP_UNFINISHED) return level;
lua_error(ms->L, "invalid pattern capture"); luaL_verror(ms->L, "invalid pattern capture");
return 0; /* to avoid warnings */ return 0; /* to avoid warnings */
} }
@@ -188,13 +188,13 @@ static const char *luaI_classend (MatchState *ms, const char *p) {
switch (*p++) { switch (*p++) {
case ESC: case ESC:
if (*p == '\0') if (*p == '\0')
lua_error(ms->L, "malformed pattern (ends with `%')"); luaL_verror(ms->L, "malformed pattern (ends with `%')");
return p+1; return p+1;
case '[': case '[':
if (*p == '^') p++; if (*p == '^') p++;
do { /* look for a `]' */ do { /* look for a `]' */
if (*p == '\0') if (*p == '\0')
lua_error(ms->L, "malformed pattern (missing `]')"); luaL_verror(ms->L, "malformed pattern (missing `]')");
if (*(p++) == ESC && *p != '\0') if (*(p++) == ESC && *p != '\0')
p++; /* skip escapes (e.g. `%]') */ p++; /* skip escapes (e.g. `%]') */
} while (*p != ']'); } while (*p != ']');
@@ -267,7 +267,7 @@ static const char *match (MatchState *ms, const char *s, const char *p);
static const char *matchbalance (MatchState *ms, const char *s, static const char *matchbalance (MatchState *ms, const char *s,
const char *p) { const char *p) {
if (*p == 0 || *(p+1) == 0) if (*p == 0 || *(p+1) == 0)
lua_error(ms->L, "unbalanced pattern"); luaL_verror(ms->L, "unbalanced pattern");
if (*s != *p) return NULL; if (*s != *p) return NULL;
else { else {
int b = *p; int b = *p;
@@ -316,7 +316,7 @@ static const char *start_capture (MatchState *ms, const char *s,
const char *p, int what) { const char *p, int what) {
const char *res; const char *res;
int level = ms->level; int level = ms->level;
if (level >= MAX_CAPTURES) lua_error(ms->L, "too many captures"); if (level >= MAX_CAPTURES) luaL_verror(ms->L, "too many captures");
ms->capture[level].init = s; ms->capture[level].init = s;
ms->capture[level].len = what; ms->capture[level].len = what;
ms->level = level+1; ms->level = level+1;
@@ -426,7 +426,7 @@ static const char *lmemfind (const char *s1, size_t l1,
static void push_onecapture (MatchState *ms, int i) { static void push_onecapture (MatchState *ms, int i) {
int l = ms->capture[i].len; int l = ms->capture[i].len;
if (l == CAP_UNFINISHED) lua_error(ms->L, "unfinished capture"); if (l == CAP_UNFINISHED) luaL_verror(ms->L, "unfinished capture");
if (l == CAP_POSITION) if (l == CAP_POSITION)
lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1);
else else
@@ -636,9 +636,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt,
if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
} }
if (isdigit(uchar(*p))) if (isdigit(uchar(*p)))
lua_error(L, "invalid format (width or precision too long)"); luaL_verror(L, "invalid format (width or precision too long)");
if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
lua_error(L, "invalid format (too long)"); luaL_verror(L, "invalid format (too long)");
form[0] = '%'; form[0] = '%';
strncpy(form+1, strfrmt, p-strfrmt+1); strncpy(form+1, strfrmt, p-strfrmt+1);
form[p-strfrmt+2] = 0; form[p-strfrmt+2] = 0;
@@ -663,7 +663,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) == '$')
lua_error(L, "obsolete `format' option (d$)"); luaL_verror(L, "obsolete `format' option (d$)");
arg++; arg++;
strfrmt = scanformat(L, strfrmt, form, &hasprecision); strfrmt = scanformat(L, strfrmt, form, &hasprecision);
switch (*strfrmt++) { switch (*strfrmt++) {
@@ -696,7 +696,7 @@ static int str_format (lua_State *L) {
} }
} }
default: /* also treat cases `pnLlh' */ default: /* also treat cases `pnLlh' */
lua_error(L, "invalid option in `format'"); luaL_verror(L, "invalid option in `format'");
} }
luaL_addlstring(&b, buff, strlen(buff)); luaL_addlstring(&b, buff, strlen(buff));
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltablib.c,v 1.1 2002/04/09 20:19:06 roberto Exp roberto $ ** $Id: ltablib.c,v 1.2 2002/04/12 19:57:29 roberto Exp roberto $
** Library for Table Manipulation ** Library for Table Manipulation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -171,12 +171,12 @@ static void auxsort (lua_State *L, int l, int u) {
for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
/* repeat ++i until a[i] >= P */ /* repeat ++i until a[i] >= P */
while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
if (i>u) lua_error(L, "invalid order function for sorting"); if (i>u) luaL_verror(L, "invalid order function for sorting");
lua_pop(L, 1); /* remove a[i] */ lua_pop(L, 1); /* remove a[i] */
} }
/* repeat --j until a[j] <= P */ /* repeat --j until a[j] <= P */
while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
if (j<l) lua_error(L, "invalid order function for sorting"); if (j<l) luaL_verror(L, "invalid order function for sorting");
lua_pop(L, 1); /* remove a[j] */ lua_pop(L, 1); /* remove a[j] */
} }
if (j<i) { if (j<i) {