aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldebug.c29
-rw-r--r--ldebug.h4
-rw-r--r--llex.c7
3 files changed, 21 insertions, 19 deletions
diff --git a/ldebug.c b/ldebug.c
index 6e4cdb35..91c3e5b7 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.113 2015/03/11 16:10:41 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.114 2015/03/28 19:14:47 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -599,19 +599,16 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
599} 599}
600 600
601 601
602static void addinfo (lua_State *L, const char *msg) { 602/* add src:line information to 'msg' */
603 CallInfo *ci = L->ci; 603const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
604 if (isLua(ci)) { /* is Lua code? */ 604 int line) {
605 char buff[LUA_IDSIZE]; /* add file:line information */ 605 char buff[LUA_IDSIZE];
606 int line = currentline(ci); 606 if (src)
607 TString *src = ci_func(ci)->p->source; 607 luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
608 if (src) 608 else { /* no source available; use "?" instead */
609 luaO_chunkid(buff, getstr(src), LUA_IDSIZE); 609 buff[0] = '?'; buff[1] = '\0';
610 else { /* no source available; use "?" instead */
611 buff[0] = '?'; buff[1] = '\0';
612 }
613 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
614 } 610 }
611 return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
615} 612}
616 613
617 614
@@ -628,10 +625,14 @@ l_noret luaG_errormsg (lua_State *L) {
628 625
629 626
630l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { 627l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
628 CallInfo *ci = L->ci;
629 const char *msg;
631 va_list argp; 630 va_list argp;
632 va_start(argp, fmt); 631 va_start(argp, fmt);
633 addinfo(L, luaO_pushvfstring(L, fmt, argp)); 632 msg = luaO_pushvfstring(L, fmt, argp); /* format message */
634 va_end(argp); 633 va_end(argp);
634 if (isLua(ci)) /* if Lua function, add source:line information */
635 luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));
635 luaG_errormsg(L); 636 luaG_errormsg(L);
636} 637}
637 638
diff --git a/ldebug.h b/ldebug.h
index e44b3f78..9c0a03a6 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp roberto $ 2** $Id: ldebug.h,v 2.13 2015/03/11 16:10:41 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -30,6 +30,8 @@ LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,
30LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 30LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
31 const TValue *p2); 31 const TValue *p2);
32LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 32LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
33LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
34 TString *src, int line);
33LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 35LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
34LUAI_FUNC void luaG_traceexec (lua_State *L); 36LUAI_FUNC void luaG_traceexec (lua_State *L);
35 37
diff --git a/llex.c b/llex.c
index 15eb29be..118a0186 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.91 2015/03/28 19:14:47 roberto Exp roberto $ 2** $Id: llex.c,v 2.92 2015/04/03 18:41:57 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,6 +16,7 @@
16#include "lua.h" 16#include "lua.h"
17 17
18#include "lctype.h" 18#include "lctype.h"
19#include "ldebug.h"
19#include "ldo.h" 20#include "ldo.h"
20#include "lgc.h" 21#include "lgc.h"
21#include "llex.h" 22#include "llex.h"
@@ -106,9 +107,7 @@ static const char *txtToken (LexState *ls, int token) {
106 107
107 108
108static l_noret lexerror (LexState *ls, const char *msg, int token) { 109static l_noret lexerror (LexState *ls, const char *msg, int token) {
109 char buff[LUA_IDSIZE]; 110 msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
110 luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE);
111 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
112 if (token) 111 if (token)
113 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); 112 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
114 luaD_throw(ls->L, LUA_ERRSYNTAX); 113 luaD_throw(ls->L, LUA_ERRSYNTAX);