https://github.com/gszr/lua-call-graph
Generate the call graph of a Lua program
https://github.com/gszr/lua-call-graph
call-graph callgraph lua
Last synced: 2 months ago
JSON representation
Generate the call graph of a Lua program
- Host: GitHub
- URL: https://github.com/gszr/lua-call-graph
- Owner: gszr
- License: mit
- Created: 2024-03-09T12:58:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-08T18:10:37.000Z (3 months ago)
- Last Synced: 2025-03-14T19:44:34.741Z (2 months ago)
- Topics: call-graph, callgraph, lua
- Language: Lua
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lua Call Graph
Generate a call graph of Lua programs.
## API
### new
Create new capture instance.
**syntax**: graph.new(cfg)
Supported configs:
* `name`: call graph name
* `filename`: name for the call graph `.dot` file (defaults to `name`)
* `ignores`: an array of function names to redact from the `.dot` file
* `separator`: the character to use as separator for spaces[^1]
* `mappings`: a translation map of function names; if a function mamed `key` is
found, it's renamed with `value`[^1]: Some internal function names might contain spaces. For example, `for iterator`.
The `separator` value will be used to replace these spaces.### :capture
**syntax**: *graph:capture()*
Starts capturing the call graph from that point in the program.
### :stop
**syntax**: graph:stop()
Stops capturing the call graph. A subsequent call to `:emit` generates the
call graph.### :emit
**syntax**: *graph:emit()*
Emits the captured call graph named `name` into the DOT file `filename`.
## Example
Given the Lua code below
```lua
local callgraph = require"callgraph"function a()
b()
endfunction b()
c()
print()
endfunction c()
local t = {"a", "b"}
for _, _ in pairs(t) do end
d()
endfunction d()
print("")
endlocal 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:
