From 8bb123f198ee72a8037a743ff2e920d5d7bbedf4 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 21 Jun 2020 19:16:50 +1000 Subject: [PATCH] added a component documentation searcher --- lib/doc.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/doc.lua b/lib/doc.lua index 34faa46..e472079 100644 --- a/lib/doc.lua +++ b/lib/doc.lua @@ -4,6 +4,7 @@ doc.searchers = {} doc.tctab = { ["string"] = 31, ["table"] = 32, + ["userdata"] = 32, ["number"] = 33, ["boolean"] = 35, ["function"] = 36 @@ -111,6 +112,31 @@ function doc.searchers.cdoc(topic) -- string -- string string -- Searches for do end end end +function doc.searchers.component(name) + local dt = {} + local addr = component.list(name)() + if addr then + for fname,_ in pairs(component.methods(addr)) do + fd = {args={},outtypes={},atypes={}} + local ds = component.doc(addr,fname) + local ins, outs, desc = ds:match("%((.-)%)") or "", ds:match("%):(.*)%-%-") or "", ds:match("%-%-(.+)") or "" + for arg in ins:gmatch("[^,%s%[%]]+") do + local an,at = arg:match("(.-):(.+)") + at = at:match("(.-)=") or at + fd.args[#fd.args+1] = {an,at} + fd.atypes[an] = at + end + for out in outs:gmatch("[^,]+") do + fd.outtypes[#fd.outtypes+1] = out:match("^%s*(.-)%s*$") + end + fd.description = desc or "" + dt[name.."."..fname] = fd + end + else + return + end + return doc.format(dt) +end function doc.docs(topic) -- string -- boolean -- Displays the documentation for *topic*, returning true, or errors. Also callable as just doc(). local lib = os.getenv("LIB") or "/boot/lib"