Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ExtReMLapin/08dbb6769bfebce678e2cc62c68098f4 to your computer and use it in GitHub Desktop.
Save ExtReMLapin/08dbb6769bfebce678e2cc62c68098f4 to your computer and use it in GitHub Desktop.
Coded that for Infflux debugger, checks if the line of a file is active (used) using a proto hack instead of editing the luajit code
require("printtable")
jit.util = require("jit.util")
local function getSubFunctions(fn)
local ret = {}
local i = -1
while true do
local const = jit.util.funck(fn, i)
if not const then return ret end
if type(const) == "proto" then
table.insert(ret, const)
end
i = i - 1
end
end
local function isFunctionLineActive(fn, line)
local linesTable;
local fnType = type(fn)
if fnType == "function" then
linesTable = debug.getinfo(fn, "L").activelines
elseif fnType == "proto" then
-- close your eyes
linesTable = {}
local bcCount = jit.util.funcinfo(fn).bytecodes
while (bcCount > 0) do
linesTable[jit.util.funcinfo(fn, bcCount-1).currentline] = true
bcCount = bcCount - 1
end
end
if linesTable[line] then return true end
local subFuncs = getSubFunctions(fn)
for k, v in ipairs(subFuncs) do
if isFunctionLineActive(v, line) then return true end
end
return false
end
local function checkActiveFile(file, line)
local fn = loadfile(file)
return isFunctionLineActive(fn, line)
end
print(checkActiveFile("CURRENT FILE HERE", 41))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment