From 95e6a182161c715f617cbaeb95308733509604b6 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 8 Jan 2019 22:13:52 +1100 Subject: [PATCH] documentation of a sort --- README.md | 8 +++++++- finddesc.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 finddesc.lua diff --git a/README.md b/README.md index fdca786..7ead303 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # OC-PsychOS2 -Operating system for OpenComputers \ No newline at end of file +A lightweight, multi-user operating system for OpenComputers + +## Documentation + +To generate function documentation, run: + + ./finddesc.lua module/* lib/* > apidoc.md diff --git a/finddesc.lua b/finddesc.lua new file mode 100644 index 0000000..513a271 --- /dev/null +++ b/finddesc.lua @@ -0,0 +1,27 @@ +local tA = {...} +local docfiles = {} +for _,file in pairs(tA) do + docfiles[file] = {} + local f = io.open(file) + local lines = {} + for l in f:read("*a"):gmatch("[^\n]+") do + if l:find("function") and not l:find("local") then + lines[#lines+1] = l + end + end + for k,v in pairs(lines) do + local name, args, desc = v:match("function%s+(.+)%s*%((.*)%)%s*%-%-%s*(.+)") + if name and args and desc then + docfiles[file][#docfiles[file]+1] = string.format("##%s(%s)\n%s",name,args,desc) + end + end +end + +for k,v in pairs(docfiles) do + if #v > 0 then + print("#"..k) + for l,m in pairs(v) do + print(m) + end + end +end