no more newlines at the end of error messages

This commit is contained in:
Roberto Ierusalimschy 2002-09-05 16:45:42 -03:00
parent b2bc3b44b6
commit 1bdde38bd2
6 changed files with 16 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.83 2002/08/08 20:08:41 roberto Exp roberto $
** $Id: lauxlib.c,v 1.84 2002/08/30 20:00:59 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -81,8 +81,7 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
luaL_where(L, 1);
lua_pushvfstring(L, fmt, argp);
va_end(argp);
lua_pushliteral(L, "\n");
lua_concat(L, 3);
lua_concat(L, 2);
return lua_error(L);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.96 2002/08/06 18:54:18 roberto Exp roberto $
** $Id: lbaselib.c,v 1.97 2002/08/08 20:08:41 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -82,8 +82,7 @@ static int luaB_error (lua_State *L) {
else { /* add extra information */
luaL_where(L, level);
lua_pushvalue(L, 1);
lua_pushliteral(L, "\n");
lua_concat(L, 3);
lua_concat(L, 2);
}
return lua_error(L);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.67 2002/08/12 17:23:12 roberto Exp roberto $
** $Id: ldblib.c,v 1.68 2002/08/16 14:45:18 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -198,21 +198,21 @@ static int errorfb (lua_State *L) {
if (lua_gettop(L) == 0)
lua_pushliteral(L, "");
else if (!lua_isstring(L, 1)) return 1; /* no string message */
lua_pushliteral(L, "stack traceback:\n");
lua_pushliteral(L, "\nstack traceback:");
while (lua_getstack(L, level++, &ar)) {
if (level > LEVELS1 && firstpart) {
/* no more than `LEVELS2' more levels? */
if (!lua_getstack(L, level+LEVELS2, &ar))
level--; /* keep going */
else {
lua_pushliteral(L, "\t...\n"); /* too many levels */
lua_pushliteral(L, "\n\t..."); /* too many levels */
while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */
level++;
}
firstpart = 0;
continue;
}
lua_pushliteral(L, "\t");
lua_pushliteral(L, "\n\t");
lua_getinfo(L, "Snl", &ar);
lua_pushfstring(L, "%s:", ar.short_src);
if (ar.currentline > 0)
@ -234,7 +234,6 @@ static int errorfb (lua_State *L) {
ar.short_src, ar.linedefined);
}
}
lua_pushliteral(L, "\n");
lua_concat(L, lua_gettop(L));
}
lua_concat(L, lua_gettop(L));

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.132 2002/08/12 17:23:12 roberto Exp roberto $
** $Id: ldebug.c,v 1.133 2002/08/20 20:03:05 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -524,14 +524,11 @@ int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
static void addinfo (lua_State *L, const char *msg) {
CallInfo *ci = L->ci;
if (!isLua(ci)) { /* no Lua code? */
luaO_pushfstring(L, "%s\n", msg); /* no extra info; just add '\n' */
}
else { /* add file:line information */
char buff[LUA_IDSIZE];
if (isLua(ci)) { /* is Lua code? */
char buff[LUA_IDSIZE]; /* add file:line information */
int line = currentline(ci);
luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
luaO_pushfstring(L, "%s:%d: %s\n", buff, line, msg);
luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
}
}

4
llex.c
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.109 2002/08/16 14:45:55 roberto Exp roberto $
** $Id: llex.c,v 1.110 2002/09/03 11:57:38 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -61,7 +61,7 @@ static void luaX_error (LexState *ls, const char *s, const char *token) {
lua_State *L = ls->L;
char buff[MAXSRC];
luaO_chunkid(buff, getstr(ls->source), MAXSRC);
luaO_pushfstring(L, "%s:%d: %s near `%s'\n", buff, ls->linenumber, s, token);
luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token);
luaD_throw(L, LUA_ERRSYNTAX);
}

7
lua.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.102 2002/08/12 17:23:12 roberto Exp roberto $
** $Id: lua.c,v 1.103 2002/08/13 15:04:59 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -87,11 +87,8 @@ static void print_usage (void) {
static void l_message (const char *pname, const char *msg) {
size_t l = strlen(msg);
if (pname) fprintf(stderr, "%s: ", pname);
fprintf(stderr, "%s", msg);
if (l > 0 && msg[l-1] != '\n') /* does not end with newline? */
fprintf(stderr, "\n"); /* add a newline */
fprintf(stderr, "%s\n", msg);
}