tools/linedebug.lua
author Kim Alvefur <zash@zash.se>
Fri, 07 Apr 2023 14:03:24 +0200
changeset 13057 8128c4f1b08b
parent 11197 5850d24a4ad3
permissions -rw-r--r--
mod_admin_shell: Allow "*" as substitute for 'nil' for easier CLI usage Since prosodyctl shell with additional arguments assumes the first two are a section:command() and any following arguments are strings, passing a bare 'nil' is not possible. In order to avoid delving into this rabbit hole, instead produce a token that alone is not really a legal JID for use as wildcard.

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");