--define lets you set conditional flags for config.ld; single module detection improved
This commit is contained in:
parent
7e53497393
commit
88d9ee4e8b
37
ldoc.lua
37
ldoc.lua
|
@ -35,7 +35,7 @@ app.require_here()
|
||||||
|
|
||||||
--- @usage
|
--- @usage
|
||||||
local usage = [[
|
local usage = [[
|
||||||
ldoc, a documentation generator for Lua, vs 1.2.0
|
ldoc, a documentation generator for Lua, vs 1.3.0
|
||||||
-d,--dir (default docs) output directory
|
-d,--dir (default docs) output directory
|
||||||
-o,--output (default 'index') output name
|
-o,--output (default 'index') output name
|
||||||
-v,--verbose verbose
|
-v,--verbose verbose
|
||||||
|
@ -52,6 +52,7 @@ ldoc, a documentation generator for Lua, vs 1.2.0
|
||||||
-x,--ext (default html) output file extension
|
-x,--ext (default html) output file extension
|
||||||
-c,--config (default config.ld) configuration name
|
-c,--config (default config.ld) configuration name
|
||||||
-i,--ignore ignore any 'no doc comment or no module' warnings
|
-i,--ignore ignore any 'no doc comment or no module' warnings
|
||||||
|
-D,--define (default none) set a flag to be used in config.ld
|
||||||
--dump debug output dump
|
--dump debug output dump
|
||||||
--filter (default none) filter output as Lua data (e.g pl.pretty.dump)
|
--filter (default none) filter output as Lua data (e.g pl.pretty.dump)
|
||||||
--tags (default none) show all references to given tags, comma-separated
|
--tags (default none) show all references to given tags, comma-separated
|
||||||
|
@ -182,6 +183,20 @@ local ldoc_contents = {
|
||||||
}
|
}
|
||||||
ldoc_contents = tablex.makeset(ldoc_contents)
|
ldoc_contents = tablex.makeset(ldoc_contents)
|
||||||
|
|
||||||
|
local function loadstr (ldoc,txt)
|
||||||
|
local chunk, err
|
||||||
|
local load
|
||||||
|
-- Penlight's Lua 5.2 compatibility has wobbled over the years...
|
||||||
|
if not rawget(_G,'loadin') then -- Penlight 0.9.5
|
||||||
|
-- Penlight 0.9.7; no more global load() override
|
||||||
|
load = load or utils.load
|
||||||
|
chunk,err = load(txt,'config',nil,ldoc)
|
||||||
|
else
|
||||||
|
chunk,err = loadin(ldoc,txt)
|
||||||
|
end
|
||||||
|
return chunk, err
|
||||||
|
end
|
||||||
|
|
||||||
-- any file called 'config.ld' found in the source tree will be
|
-- any file called 'config.ld' found in the source tree will be
|
||||||
-- handled specially. It will be loaded using 'ldoc' as the environment.
|
-- handled specially. It will be loaded using 'ldoc' as the environment.
|
||||||
local function read_ldoc_config (fname)
|
local function read_ldoc_config (fname)
|
||||||
|
@ -189,22 +204,15 @@ local function read_ldoc_config (fname)
|
||||||
if directory == '' then
|
if directory == '' then
|
||||||
directory = '.'
|
directory = '.'
|
||||||
end
|
end
|
||||||
local err
|
local chunk, err, ok
|
||||||
if args.filter == 'none' then
|
if args.filter == 'none' then
|
||||||
print('reading configuration from '..fname)
|
print('reading configuration from '..fname)
|
||||||
end
|
end
|
||||||
local txt,not_found = utils.readfile(fname)
|
local txt,not_found = utils.readfile(fname)
|
||||||
if txt then
|
if txt then
|
||||||
-- Penlight defines loadin for Lua 5.1 as well
|
chunk, err = loadstr(ldoc,txt)
|
||||||
local chunk
|
|
||||||
if not rawget(_G,'loadin') then -- Penlight 0.9.5
|
|
||||||
if utils.load then load = utils.load end -- Penlight 0.9.7; no more global load() override
|
|
||||||
chunk,err = load(txt,nil,nil,ldoc)
|
|
||||||
else
|
|
||||||
chunk,err = loadin(ldoc,txt)
|
|
||||||
end
|
|
||||||
if chunk then
|
if chunk then
|
||||||
local ok
|
if args.define ~= 'none' then ldoc[args.define] = true end
|
||||||
ok,err = pcall(chunk)
|
ok,err = pcall(chunk)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -443,9 +451,12 @@ local project = ProjectMap()
|
||||||
local module_list = List()
|
local module_list = List()
|
||||||
module_list.by_name = {}
|
module_list.by_name = {}
|
||||||
|
|
||||||
|
local modcount = 0
|
||||||
|
|
||||||
for F in file_list:iter() do
|
for F in file_list:iter() do
|
||||||
for mod in F.modules:iter() do
|
for mod in F.modules:iter() do
|
||||||
if not first_module then first_module = mod end
|
if not first_module then first_module = mod end
|
||||||
|
if doc.code_tag(mod.type) then modcount = modcount + 1 end
|
||||||
module_list:append(mod)
|
module_list:append(mod)
|
||||||
module_list.by_name[mod.name] = mod
|
module_list.by_name[mod.name] = mod
|
||||||
end
|
end
|
||||||
|
@ -469,6 +480,9 @@ table.sort(module_list,function(m1,m2)
|
||||||
return m1.name < m2.name
|
return m1.name < m2.name
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
ldoc.single = modcount == 1 and first_module or nil
|
||||||
|
|
||||||
|
|
||||||
-------- three ways to dump the object graph after processing -----
|
-------- three ways to dump the object graph after processing -----
|
||||||
|
|
||||||
-- ldoc -m will give a quick & dirty dump of the module's documentation;
|
-- ldoc -m will give a quick & dirty dump of the module's documentation;
|
||||||
|
@ -571,7 +585,6 @@ if args.style == '!' or args.template == '!' then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ldoc.single = #module_list == 1 and first_module or nil
|
|
||||||
ldoc.log = print
|
ldoc.log = print
|
||||||
ldoc.kinds = project
|
ldoc.kinds = project
|
||||||
ldoc.modules = module_list
|
ldoc.modules = module_list
|
||||||
|
|
Loading…
Reference in New Issue