mirror of https://github.com/Hilbis/Hilbish
Compare commits
2 Commits
339677884b
...
8935426d08
Author | SHA1 | Date |
---|---|---|
sammyette | 8935426d08 | |
sammyette | 316a818c2f |
|
@ -0,0 +1,72 @@
|
||||||
|
local fs = require 'fs'
|
||||||
|
local emmyPattern = '^%-%-%- (.+)'
|
||||||
|
local modpattern = '^%-+ @module (%w+)'
|
||||||
|
local pieces = {}
|
||||||
|
|
||||||
|
local files = fs.readdir 'nature'
|
||||||
|
for _, fname in ipairs(files) do
|
||||||
|
local isScript = fname:match'%.lua$'
|
||||||
|
if not isScript then goto continue end
|
||||||
|
|
||||||
|
local f = io.open(string.format('nature/%s', fname))
|
||||||
|
local header = f:read '*l'
|
||||||
|
local mod = header:match(modpattern)
|
||||||
|
if not mod then goto continue end
|
||||||
|
|
||||||
|
print(fname, mod)
|
||||||
|
pieces[mod] = {}
|
||||||
|
|
||||||
|
local docPiece = {}
|
||||||
|
for line in f:lines() do
|
||||||
|
if line == header then goto continue2 end
|
||||||
|
if not line:match(emmyPattern) then
|
||||||
|
if line:match '^function' then
|
||||||
|
local pattern = (string.format('^function %s%%.', mod) .. '(%w+)')
|
||||||
|
local funcName = line:match(pattern)
|
||||||
|
if not funcName then goto continue2 end
|
||||||
|
print(line)
|
||||||
|
print(pattern)
|
||||||
|
print(funcName)
|
||||||
|
pieces[iface][funcName] = docPiece
|
||||||
|
end
|
||||||
|
docPiece = {}
|
||||||
|
goto continue2
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(docPiece, line)
|
||||||
|
::continue2::
|
||||||
|
end
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
for iface, dps in pairs(pieces) do
|
||||||
|
local mod = iface:match '(%w+)%.' or 'nature'
|
||||||
|
local path = string.format('luadocs/api/%s/%s.md', mod, iface)
|
||||||
|
local f <close> = io.open(path, 'a+')
|
||||||
|
print(f)
|
||||||
|
|
||||||
|
print(mod, path)
|
||||||
|
fs.mkdir(fs.dir(path), true)
|
||||||
|
|
||||||
|
for func, docs in pairs(dps) do
|
||||||
|
local params = table.filter(docs, function(t)
|
||||||
|
return t:match '^%-%-%- @param'
|
||||||
|
end)
|
||||||
|
f:write(string.format('## %s(', func))
|
||||||
|
for i, str in ipairs(params) do
|
||||||
|
if i ~= 1 then
|
||||||
|
f:write ', '
|
||||||
|
end
|
||||||
|
f:write(str:match '^%-%-%- @param ([%w]+) ')
|
||||||
|
end
|
||||||
|
f:write(')\n')
|
||||||
|
|
||||||
|
for _, str in ipairs(docs) do
|
||||||
|
if not str:match '^%-%-%- @' then
|
||||||
|
f:write(str:match '^%-%-%- (.+)' .. '\n')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
f:write('\n')
|
||||||
|
end
|
||||||
|
f:flush()
|
||||||
|
end
|
|
@ -1,3 +1,4 @@
|
||||||
|
-- @module dirs
|
||||||
local fs = require 'fs'
|
local fs = require 'fs'
|
||||||
|
|
||||||
local dirs = {}
|
local dirs = {}
|
||||||
|
@ -11,8 +12,8 @@ dirs.recentDirs = {}
|
||||||
dirs.recentSize = 10
|
dirs.recentSize = 10
|
||||||
|
|
||||||
--- Get (and remove) a `num` of entries from recent directories.
|
--- Get (and remove) a `num` of entries from recent directories.
|
||||||
--- @param num number
|
-- @param num number
|
||||||
--- @param remove boolean Whether to remove items
|
-- @param remove boolean Whether to remove items
|
||||||
function dirRecents(num, remove)
|
function dirRecents(num, remove)
|
||||||
num = num or 1
|
num = num or 1
|
||||||
local entries = {}
|
local entries = {}
|
||||||
|
@ -34,7 +35,7 @@ function dirRecents(num, remove)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Look at `num` amount of recent directories, starting from the latest.
|
--- Look at `num` amount of recent directories, starting from the latest.
|
||||||
--- @param num? number
|
-- @param num? number
|
||||||
function dirs.peak(num)
|
function dirs.peak(num)
|
||||||
return dirRecents(num)
|
return dirRecents(num)
|
||||||
end
|
end
|
||||||
|
@ -51,19 +52,19 @@ function dirs.push(d)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Remove `num` amount of dirs from the recent directories.
|
--- Remove `num` amount of dirs from the recent directories.
|
||||||
--- @param num number
|
-- @param num number
|
||||||
function dirs.pop(num)
|
function dirs.pop(num)
|
||||||
return dirRecents(num, true)
|
return dirRecents(num, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get entry from recent directories.
|
--- Get entry from recent directories.
|
||||||
--- @param idx number
|
-- @param idx number
|
||||||
function dirs.recent(idx)
|
function dirs.recent(idx)
|
||||||
return dirs.recentDirs[idx]
|
return dirs.recentDirs[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sets the old directory.
|
--- Sets the old directory.
|
||||||
--- @param d string
|
-- @param d string
|
||||||
function dirs.setOld(d)
|
function dirs.setOld(d)
|
||||||
ok, d = pcall(fs.abs, d)
|
ok, d = pcall(fs.abs, d)
|
||||||
assert(ok, 'could not turn "' .. d .. '"into an absolute path')
|
assert(ok, 'could not turn "' .. d .. '"into an absolute path')
|
||||||
|
|
Loading…
Reference in New Issue