-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocgen.lua
More file actions
executable file
·74 lines (58 loc) · 1.64 KB
/
Copy pathdocgen.lua
File metadata and controls
executable file
·74 lines (58 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env lua
local lua_api_dir = "./src/lua/"
---@param file_name string
---@return string?
local function generate_docs(file_name)
local file = io.open(lua_api_dir .. file_name, "r")
if file == nil then
return nil
end
local first_line = file:read("l")
local module_name = first_line:match("//! (%S+)")
if module_name == nil then
file:close()
return nil
end
local output = "\n" .. module_name .. " = {}\n"
local annotations = {}
local params = {}
for line in file:lines() do
if line:match("^%s*/// %-%-%-") then
local line = line:gsub("^%s*/// %-%-%-", "---")
if line:match("@param %.%.%.") then
params[#params + 1] = "..."
elseif line:match("@param") then
params[#params + 1] = line:match("@param%s([%a_]+)%s")
end
annotations[#annotations + 1] = line
elseif #annotations ~= 0 then
local doc = "\n" .. table.concat(annotations, "\n")
if line:match("^%s*pub fn ") then
doc = doc .. string.format(
"\n%s.%s = function(%s) end",
module_name,
line:match("pub fn ([%w_]+)%("),
table.concat(params, ", ")
)
end
output = output .. doc .. "\n"
annotations = {}
params = {}
end
end
file:close()
return output
end
local files, err = io.popen("ls " .. lua_api_dir)
if files == nil then error(err) end
local docs = "---@meta [mez]\nmez = {}\n"
for filename in files:lines() do
local d = generate_docs(filename)
if d ~= nil then
docs = docs .. d
end
end
local out, err = io.open("./runtime/mez_types.lua", "w")
if out == nil then error(err) end
out:write(docs)
out:close()