diff options
author | Karl Berry <karl@freefriends.org> | 2019-01-17 21:28:52 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-01-17 21:28:52 +0000 |
commit | ba0bdf056bfd0604de23047d0feee9272232713b (patch) | |
tree | 804780ca9466935234d6f6db659e0c94a01574b7 /Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua | |
parent | d99b42e0fca3ee0a7fbeb587d4ec6c2d8f9076c5 (diff) |
lualibs (17jan19)
git-svn-id: svn://tug.org/texlive/trunk@49741 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua index 9488a728b61..6932e8804d3 100644 --- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua +++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-deb.lua @@ -10,9 +10,6 @@ if not modules then modules = { } end modules ['util-deb'] = { -- bound to a variable, like node.new, node.copy etc (contrary to for instance -- node.has_attribute which is bound to a has_attribute local variable in mkiv) -local debug = require "debug" - -local getinfo, sethook = debug.getinfo, debug.sethook local type, next, tostring, tonumber = type, next, tostring, tonumber local format, find, sub, gsub = string.format, string.find, string.sub, string.gsub local insert, remove, sort = table.insert, table.remove, table.sort @@ -109,6 +106,9 @@ setmetatableindex(names,function(t,name) return v end) +local getinfo = nil +local sethook = nil + local function hook(where) local f = getinfo(2,"nSl") if f then @@ -240,6 +240,27 @@ function debugger.showstats(printer,threshold) -- table.save("luatex-profile.lua",names) end +local function getdebug() + if sethook and getinfo then + return + end + if not debug then + local okay + okay, debug = pcall(require,"debug") + end + if type(debug) ~= "table" then + return + end + getinfo = debug.getinfo + sethook = debug.sethook + if type(getinfo) ~= "function" then + getinfo = nil + end + if type(sethook) ~= "function" then + sethook = nil + end +end + function debugger.savestats(filename,threshold) local f = io.open(filename,'w') if f then @@ -249,7 +270,8 @@ function debugger.savestats(filename,threshold) end function debugger.enable() - if nesting == 0 then + getdebug() + if sethook and getinfo and nesting == 0 then running = true if initialize then initialize() @@ -271,7 +293,7 @@ function debugger.disable() if nesting > 0 then nesting = nesting - 1 end - if nesting == 0 then + if sethook and getinfo and nesting == 0 then sethook() end end @@ -294,20 +316,25 @@ end -- from the lua book: local function showtraceback(rep) -- from lua site / adapted - local level = 2 -- we don't want this function to be reported - local reporter = rep or report - while true do - local info = getinfo(level, "Sl") - if not info then - break - elseif info.what == "C" then - reporter("%2i : %s",level-1,"C function") - else - reporter("%2i : %s : %s",level-1,info.short_src,info.currentline) + getdebug() + if getinfo then + local level = 2 -- we don't want this function to be reported + local reporter = rep or report + while true do + local info = getinfo(level, "Sl") + if not info then + break + elseif info.what == "C" then + reporter("%2i : %s",level-1,"C function") + else + reporter("%2i : %s : %s",level-1,info.short_src,info.currentline) + end + level = level + 1 end - level = level + 1 end end debugger.showtraceback = showtraceback -- debug.showtraceback = showtraceback + +-- showtraceback() |