Skip to content

Instantly share code, notes, and snippets.

@lincerely
Last active February 12, 2021 21:05
Show Gist options
  • Save lincerely/1387cd0c9e9dc0368dbe7011a7044551 to your computer and use it in GitHub Desktop.
Save lincerely/1387cd0c9e9dc0368dbe7011a7044551 to your computer and use it in GitHub Desktop.
generate lua class diagram in graphviz format, compatible with rxi's class module (https://github.com/rxi/classic/blob/master/classic.lua)
#!/bin/sh
# generate lua class diagram in graphviz format
# example: ./lua-class.sh *.lua > class.gv
echo "digraph hierarchy {"
echo "\tsize = \"5,5\""
echo "\tnode[shape=record,style=filled,fillcolor=gray95]"
echo "\tedge[dir=back,arrowtail=empty]"
grep "^function" "$@" |\
sed "s/.*function //" |\
awk '{ match($0, /[:.]/); cn=substr($0,1,RSTART-1); f=substr($0,RSTART+1,length($0)-RSTART); c[cn] = c[cn] f "\\n";} END { for (i in c) { printf "%s[label=\"{%s|%s}\"]\n", i, i, c[i] }}'
grep ":extend()" "$@" |\
sed "s/[^ ]* //" |\
sed "s/:extend()//" |\
sed "s/\([^ ]*\) \?= \?\([^ ]*\)/\t\2 -> \1/"
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment