瀏覽代碼

added doc() support for pre-compiled API documentation, wrote a generator for it, and included that in the build script

pull/3/head
XeonSquared 4 年之前
父節點
當前提交
7ddece288b
共有 3 個文件被更改,包括 68 次插入1 次删除
  1. +2
    -1
      build.sh
  2. +51
    -0
      gendoc.lua
  3. +15
    -0
      lib/doc.lua

+ 2
- 1
build.sh 查看文件

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
LUA=${LUA:-lua} LUA=${LUA:-lua}
rm -r target/* rm -r target/*
mkdir target &>/dev/null
mkdir -p target/doc &>/dev/null
$LUA luapreproc.lua module/init.lua target/init.lua $LUA luapreproc.lua module/init.lua target/init.lua
echo _OSVERSION=\"PsychOS 2.0a2-$(git rev-parse --short HEAD)\" > target/version.lua echo _OSVERSION=\"PsychOS 2.0a2-$(git rev-parse --short HEAD)\" > target/version.lua
cat target/version.lua target/init.lua > target/tinit.lua cat target/version.lua target/init.lua > target/tinit.lua
@@ -10,4 +10,5 @@ cp -r service/ lib/ cfg/ target/
rm target/version.lua rm target/version.lua
rm -r doc/ rm -r doc/
$LUA finddesc.lua doc/ $(find lib/ module/ -type f|sort) $LUA finddesc.lua doc/ $(find lib/ module/ -type f|sort)
$LUA gendoc.lua target/doc/kernel.dict $(find module/ -type f|sort)
pandoc doc/apidoc.md docs-metadata.yml --template=template.tex -o doc/apidoc.pdf pandoc doc/apidoc.md docs-metadata.yml --template=template.tex -o doc/apidoc.pdf

+ 51
- 0
gendoc.lua 查看文件

@@ -0,0 +1,51 @@
#!/usr/bin/env lua
local doc = require "lib/doc"
local ser = require "lib/serialization"
local tA = {...}

local outpath = table.remove(tA,1)

print(outpath)

local function formatDocs(fd)
local rs = ""
for name,finfo in pairs(fd) do
if rs:len() > 0 then
rs = rs .. "\n\n"
end
local as = ""
for k,v in pairs(finfo.args) do
if k > 1 then
as = as .. ", "
end
as = as .. v[1]
if v[2] then
as = as .. "^"..v[2].."^"
end
end
local rt = ""
for k,v in pairs(finfo.outtypes or {}) do
if rt:len() > 0 then
rt = rt .. ", "
else
rt = ": "
end
rt = rt .. v
end
rs = string.format("%s## %s(%s)%s\n%s",rs,name,as,rt,finfo.description)
end
return rs
end

local ad = io.open(outpath,"wb")

for k,v in pairs(tA) do
local fd = doc.parsefile(v)
local ds = ser.serialize(fd)
local tn = v:match("/(.+)$")
if ds:len() > 3 then
ad:write(tn.."\t"..ds:gsub("\n",""):gsub(", +",",").."\n")
end
end

ad:close()

+ 15
- 0
lib/doc.lua 查看文件

@@ -1,3 +1,4 @@
local _,serial = pcall(require,"serialization")
local doc = {} local doc = {}
doc.searchers = {} doc.searchers = {}
doc.tctab = { doc.tctab = {
@@ -96,6 +97,20 @@ function doc.searchers.lib(name) -- string -- string string -- Tries to find a d
if not dt then return false, "unable to find documentation for "..tostring(name) end if not dt then return false, "unable to find documentation for "..tostring(name) end
return doc.format(dt) return doc.format(dt)
end end
function doc.searchers.cdoc(topic) -- string -- string string -- Searches for documentation labelled as *topic* in .dict files under /boot/doc/
if not serial then return end
for k,v in ipairs(fs.list("/boot/doc")) do
if v:sub(-5) == ".dict" then
local f=io.open("/boot/doc/"..v,"rb")
for line in f:lines() do
local mname, docs = line:match("^(.-)\t(.+)$")
if mname == topic or mname == topic..".lua" then
return doc.format(serial.unserialize(docs))
end
end
end
end
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"


Loading…
取消
儲存