diff options
author | Marius <mariausol@gmail.com> | 2010-08-20 10:35:18 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2010-08-20 10:35:18 +0300 |
commit | 20da4ce347921be291c8804041bd8756e3bf1707 (patch) | |
tree | e079545741aeb84163b5888e77449c780e0233d6 /tex/context/base/trac-deb.lua | |
parent | 7d7e0d3c8d778650105cfb479f31a2bb54d69d50 (diff) | |
download | context-20da4ce347921be291c8804041bd8756e3bf1707.tar.gz |
beta 2010.08.20 00:00
Diffstat (limited to 'tex/context/base/trac-deb.lua')
-rw-r--r-- | tex/context/base/trac-deb.lua | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/tex/context/base/trac-deb.lua b/tex/context/base/trac-deb.lua index b631450f8..7e8f089a0 100644 --- a/tex/context/base/trac-deb.lua +++ b/tex/context/base/trac-deb.lua @@ -8,7 +8,7 @@ if not modules then modules = { } end modules ['trac-deb'] = { local lpeg = lpeg local lpegmatch = lpeg.match -local format, concat = string.format, table.concat +local format, concat, match = string.format, table.concat, string.match local tonumber, tostring = tonumber, tostring local texdimen, textoks, texcount = tex.dimen, tex.toks, tex.count @@ -92,10 +92,29 @@ function tracers.knownlist(name) return l and #l > 0 end -function tracers.showlines(filename,linenumber,offset) +function tracers.showlines(filename,linenumber,offset,errorstr) local data = io.loaddata(filename) local lines = data and string.splitlines(data) if lines and #lines > 0 then + -- this does not work yet as we cannot access the last lua error + -- table.print(status.list()) + -- this will be a plugin sequence + local what, where = match(errorstr,"LuaTeX error <main (%a+) instance>:(%d+)") + if what and where then + -- lua error: linenumber points to last line + local start, stop = "\\start" .. what .. "code", "\\stop" .. what .. "code" + if lines[linenumber] == start then + local n = linenumber + for i=n,1,-1 do + if lines[i] == start then + local n = i + tonumber(where) + if n <= linenumber then + linenumber = n + end + end + end + end + end offset = tonumber(offset) or 10 linenumber = tonumber(linenumber) or 10 local start = math.max(linenumber - offset,1) @@ -124,8 +143,9 @@ function tracers.printerror(offset) -- currently we still get the error message printed to the log/console so we -- add a bit of spacing around our variant texio.write_nl("\n") - report_system("error on line %s in file %s: %s ...\n",linenumber,filename,status.lasterrorstring or "?") -- lua error? - texio.write_nl(tracers.showlines(filename,linenumber,offset),"\n") + local errorstr = status.lasterrorstring or "?" + report_system("error on line %s in file %s: %s ...\n",linenumber,filename,errorstr) -- lua error? + texio.write_nl(tracers.showlines(filename,linenumber,offset,errorstr),"\n") end end @@ -194,7 +214,7 @@ local debugger = utilities.debugger local function trace_calls(n) debugger.enable() - luatex.register_stop_actions(function() + luatex.registerstopactions(function() debugger.disable() debugger.savestats(tex.jobname .. "-luacalls.log",tonumber(n)) end) |