summaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-09-12 15:41:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-09-12 15:41:43 -0300
commite143fed484a758a48bac742bf4b60b7510a9bd65 (patch)
tree042adbbdd4cb35cdfd8f9d64e022bc58cef77b05 /lbaselib.c
parent01ce1ce48c20bbb97d04460ebe97de3a7751678e (diff)
downloadlua-github-e143fed484a758a48bac742bf4b60b7510a9bd65.tar.gz
better standard error messages
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/lbaselib.c b/lbaselib.c
index df1f9bd2..e8cbaca6 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.1 2000/09/05 19:33:56 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.2 2000/09/12 13:49:05 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -14,6 +14,7 @@
#include "lua.h"
#include "lauxlib.h"
+#include "luadebug.h"
#include "lualib.h"
@@ -33,15 +34,21 @@ static int luaB__ALERT (lua_State *L) {
** The library `liolib' redefines _ERRORMESSAGE for better error information.
*/
static int luaB__ERRORMESSAGE (lua_State *L) {
- lua_settop(L, 1);
- lua_getglobals(L);
- lua_pushstring(L, LUA_ALERT);
- lua_rawget(L, -2);
+ luaL_checktype(L, 1, "string");
+ lua_getglobal(L, LUA_ALERT);
if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
- luaL_checktype(L, 1, "string");
- lua_pushvalue(L, -1); /* function to be called */
+ lua_Debug ar;
lua_pushstring(L, "error: ");
lua_pushvalue(L, 1);
+ if (lua_getstack(L, 1, &ar)) {
+ lua_getinfo(L, "Sl", &ar);
+ if (ar.source && ar.currentline > 0) {
+ char buff[100];
+ sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
+ lua_pushstring(L, buff);
+ lua_concat(L, 2);
+ }
+ }
lua_pushstring(L, "\n");
lua_concat(L, 3);
lua_call(L, 1, 0);