aboutsummaryrefslogtreecommitdiff
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
parent01ce1ce48c20bbb97d04460ebe97de3a7751678e (diff)
downloadlua-e143fed484a758a48bac742bf4b60b7510a9bd65.tar.gz
lua-e143fed484a758a48bac742bf4b60b7510a9bd65.tar.bz2
lua-e143fed484a758a48bac742bf4b60b7510a9bd65.zip
better standard error messages
-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 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.1 2000/09/05 19:33:56 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.2 2000/09/12 13:49:05 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,6 +14,7 @@
14#include "lua.h" 14#include "lua.h"
15 15
16#include "lauxlib.h" 16#include "lauxlib.h"
17#include "luadebug.h"
17#include "lualib.h" 18#include "lualib.h"
18 19
19 20
@@ -33,15 +34,21 @@ static int luaB__ALERT (lua_State *L) {
33** The library `liolib' redefines _ERRORMESSAGE for better error information. 34** The library `liolib' redefines _ERRORMESSAGE for better error information.
34*/ 35*/
35static int luaB__ERRORMESSAGE (lua_State *L) { 36static int luaB__ERRORMESSAGE (lua_State *L) {
36 lua_settop(L, 1); 37 luaL_checktype(L, 1, "string");
37 lua_getglobals(L); 38 lua_getglobal(L, LUA_ALERT);
38 lua_pushstring(L, LUA_ALERT);
39 lua_rawget(L, -2);
40 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ 39 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
41 luaL_checktype(L, 1, "string"); 40 lua_Debug ar;
42 lua_pushvalue(L, -1); /* function to be called */
43 lua_pushstring(L, "error: "); 41 lua_pushstring(L, "error: ");
44 lua_pushvalue(L, 1); 42 lua_pushvalue(L, 1);
43 if (lua_getstack(L, 1, &ar)) {
44 lua_getinfo(L, "Sl", &ar);
45 if (ar.source && ar.currentline > 0) {
46 char buff[100];
47 sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
48 lua_pushstring(L, buff);
49 lua_concat(L, 2);
50 }
51 }
45 lua_pushstring(L, "\n"); 52 lua_pushstring(L, "\n");
46 lua_concat(L, 3); 53 lua_concat(L, 3);
47 lua_call(L, 1, 0); 54 lua_call(L, 1, 0);