added example for red-black tree presented as Lua table (from lua-rbtree.git)
[luagraph.git] / examples / modgraph.lua
blobedd3a5246557d073229329dd4b025ece27833a19
1 -- display the kernel module dependencies
3 -- author: John Ellson <ellson@research.att.com>
4 -- modified: Herbert Leuwer <herbert.leuwer@gmx.de>
6 local gr = require "graph"
8 local modules = io.lines('/proc/modules')
10 local g = gr.open("G")
13 -- Default values
15 g:declare{
16 graph = {
17 rankdir = "LR",
18 size = "6.5 6.5",
19 nodesep=0.05
21 node = {
22 shape = "box",
23 width = 0,
24 height = 0,
25 margin = 0.03,
26 fontsize = 8,
27 fontname = "helvetica"
29 edge = {
30 arrowsize = 0.4
35 -- Run through the modules database
36 -- and build nodes and edges
38 for rec in modules do
39 for mod, usedbylist in string.gfind(rec, "([_%w]+) %w+ %w+ ([-,_%w]+)") do
40 n = g:node(mod)
41 for usedby in string.gfind(usedbylist, "([-_%w]+)") do
42 if (usedby ~= '-') and (usedby ~= '') then
43 n:edge(g:node(usedby))
44 end
45 end
46 end
47 end
49 g:layout()
50 g:show()
51 g:render('png', "out.png")
52 g:close()