added a component documentation searcher

This commit is contained in:
Izaya 2020-06-21 19:16:50 +10:00
parent 3f82d96b8e
commit 8bb123f198

View File

@ -4,6 +4,7 @@ doc.searchers = {}
doc.tctab = { doc.tctab = {
["string"] = 31, ["string"] = 31,
["table"] = 32, ["table"] = 32,
["userdata"] = 32,
["number"] = 33, ["number"] = 33,
["boolean"] = 35, ["boolean"] = 35,
["function"] = 36 ["function"] = 36
@ -111,6 +112,31 @@ function doc.searchers.cdoc(topic) -- string -- string string -- Searches for do
end end
end 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(). 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" local lib = os.getenv("LIB") or "/boot/lib"