fixed graph._SYSTEM for Linux
[luagraph.git] / examples / run.lua
blobf6cbe5b2a26a750d7b00d12b65f80ccb738f61ff
1 gr = require "graph"
3 if #arg < 1 then
4 print("usage: lua run.lua FILE")
5 os.exit(-1)
6 end
8 --
9 -- For simple formatted printing
11 local function printf(fmt, ...)
12 print(string.format(fmt, ...))
13 end
15 local function gshow(g)
16 local fn = os.tmpname() .. ".dot"
17 g:write(fn)
18 os.execute("dotty "..fn)
19 os.remove(fn)
20 end
22 -- Provide simple reference for frequently used functions (optional)
23 node, edge, subgraph, cluster, digraph, strictdigraph, ugraph =
24 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph, gr.graph
26 local f, err = assert(loadfile(arg[1]))
27 local g = f()
29 printf("Generated 'dot' format:")
30 g:write()
31 gshow(g)
32 g:close()