aboutsummaryrefslogtreecommitdiffstats
path: root/tools/linedebug.lua
blob: 96214cc8a113a57616223719df6ba238edf9b040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local data = {}
local getinfo = debug.getinfo;
local function linehook(ev, li)
	local S = getinfo(2, "S");
	if S and S.source and S.source:match"^@" then
		local file = S.source:sub(2);
		local lines = data[file];
		if not lines then
			lines = {};
			data[file] = lines;
			for line in io.lines(file) do
				lines[#lines+1] = line;
			end
		end
		io.stderr:write(ev, " ", file, " ", li, " ", lines[li], "\n");
	end
end
debug.sethook(linehook, "l");