Repository navigation
Expand file tree
/
Copy pathDebugFunction.lua
More file actions
51 lines (37 loc) · 1.68 KB
/
Copy pathDebugFunction.lua
File metadata and controls
51 lines (37 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Michael Nietzold
-- https://github.com/CapsAdmin/oohh/tree/master/mmyy/lua/platforms/standard/extensions
-- https://github.com/CapsAdmin/goluwa/tree/master/core/lua/libraries/extensions
-- similar debug info here: https://github.com/CapsAdmin/oohh/blob/master/mmyy/lua/platforms/standard/meta/function.lua
-- better getInfo: https://github.com/Chain-of-Insight/nomsu/blob/9c04fab370b2b963b561c5c843f720ddcf105ef4/error_handling.moon
-- enhanced: https://github.com/GitoriousLispBackup/praxis/blob/master/prods/Cognitive/dribble.lua
local function getFunctionInfo(fun)
return debug.getinfo(fun, "S")
end
function getFunctionLocation(fun)
local info = getFunctionInfo(fun)
return info.source .. ":" .. info.linedefined .. "-" .. info.lastlinedefined
end
function getFunctionBody(fun)
local info = getFunctionInfo(fun)
local sourcePath = info.source:match("@?(.*)")
local sourceText = readSource(sourcePath, info.linedefined, info.lastlinedefined)
return table.concat(sourceText, "\n")
end
function getFunctionSignature(fun)
return getFunctionBody(fun):match("([^\n]+)")
end
function getHammerspoonFunctionName(fun)
local info = getFunctionInfo(fun)
local signature = getFunctionSignature(fun)
local moduleName = info.source:match("/extensions/hs/(.-)%.lua$")
local functionName = signature:match("module%.([%w_]+)%s*=%s*function")
if moduleName and functionName then
return "hs." .. moduleName .. "." .. functionName
end
return signature
end
-- TODO: BETTER: debugFunctionBody
function debugFunction(fun)
print("Source.path:\n\n" .. getFunctionLocation(fun) .. "\n\n")
print("Source.body:\n\n" .. getFunctionBody(fun) .. "\n\n")
end