Generate a call graph of Lua programs.
Create new capture instance.
syntax: graph.new(cfg)
Supported configs:
name: call graph namefilename: name for the call graph.dotfile (defaults toname)ignores: an array of function names to redact from the.dotfileseparator: the character to use as separator for spaces1mappings: a translation map of function names; if a function mamedkeyis found, it's renamed withvalue
syntax: graph:capture()
Starts capturing the call graph from that point in the program.
syntax: graph:stop()
Stops capturing the call graph. A subsequent call to :emit generates the
call graph.
syntax: graph:emit()
Emits the captured call graph named name into the DOT file filename.
Given the Lua code below
local callgraph = require"callgraph"
function a()
b()
end
function b()
c()
print()
end
function c()
local t = {"a", "b"}
for _, _ in pairs(t) do end
d()
end
function d()
print("")
end
local g = callgraph.new({
name = "callgraph",
filename = "graph.dot",
ignores = {"something"},
})
g:capture()
pcall(a) -- this one is found
pcall(function() end) -- this one cannot be found - so shows as unknown
g:stop()
c()
g:emit()the library outputs the following call graph:
Footnotes
-
Some internal function names might contain spaces. For example,
for iterator. Theseparatorvalue will be used to replace these spaces. ↩