improved varargs support; updated example to show this and tparam usage
This commit is contained in:
parent
ecd6b4cfa5
commit
38c8f187b3
18
ldoc/doc.lua
18
ldoc/doc.lua
|
@ -338,6 +338,7 @@ end
|
||||||
|
|
||||||
function Item:finish()
|
function Item:finish()
|
||||||
local tags = self.tags
|
local tags = self.tags
|
||||||
|
local quote = tools.quote
|
||||||
self.name = read_del(tags,'name')
|
self.name = read_del(tags,'name')
|
||||||
self.type = read_del(tags,'class')
|
self.type = read_del(tags,'class')
|
||||||
self.modifiers = extract_tag_modifiers(tags)
|
self.modifiers = extract_tag_modifiers(tags)
|
||||||
|
@ -375,20 +376,19 @@ function Item:finish()
|
||||||
end
|
end
|
||||||
-- not all arguments may be commented: we use the formal arguments
|
-- not all arguments may be commented: we use the formal arguments
|
||||||
-- if available as the authoritative list, and warn if there's an inconsistency.
|
-- if available as the authoritative list, and warn if there's an inconsistency.
|
||||||
-- A formal argument of ... may match any number of params, however.
|
|
||||||
if self.formal_args then
|
if self.formal_args then
|
||||||
local fargs = self.formal_args
|
local fargs = self.formal_args
|
||||||
if #fargs ~= 1 then
|
if #fargs ~= 1 then
|
||||||
local pnames, pcomments = names, comments
|
local pnames, pcomments = names, comments
|
||||||
names, comments = List(),List()
|
names, comments = List(),List()
|
||||||
|
local varargs = fargs[#fargs] == '...'
|
||||||
for i,name in ipairs(fargs) do
|
for i,name in ipairs(fargs) do
|
||||||
if params then -- explicit set of param tags
|
if params then -- explicit set of param tags
|
||||||
local varargs = name == '...'
|
|
||||||
if pnames[i] ~= name and not varargs then
|
if pnames[i] ~= name and not varargs then
|
||||||
if pnames[i] then
|
if pnames[i] then
|
||||||
self:warning("param and formal argument name mismatch: '"..name.."' '"..pnames[i].."'")
|
self:warning("param and formal argument name mismatch: "..quote(name).." "..quote(pnames[i]))
|
||||||
else
|
else
|
||||||
self:warning("undocumented formal argument: '"..name.."'")
|
self:warning("undocumented formal argument: "..quote(name))
|
||||||
end
|
end
|
||||||
elseif varargs then
|
elseif varargs then
|
||||||
name = pnames[i]
|
name = pnames[i]
|
||||||
|
@ -398,9 +398,15 @@ function Item:finish()
|
||||||
-- ldoc allows comments in the formal arg list to be used
|
-- ldoc allows comments in the formal arg list to be used
|
||||||
comments:append (fargs.comments[name] or pcomments[i] or '')
|
comments:append (fargs.comments[name] or pcomments[i] or '')
|
||||||
end
|
end
|
||||||
if #pnames > #fargs and fargs[#fargs] ~= '...' then
|
-- A formal argument of ... may match any number of params, however.
|
||||||
|
if #pnames > #fargs then
|
||||||
for i = #fargs+1,#pnames do
|
for i = #fargs+1,#pnames do
|
||||||
self:warning("extra param with no formal argument: "..pnames[i])
|
if not varargs then
|
||||||
|
self:warning("extra param with no formal argument: "..quote(pnames[i]))
|
||||||
|
else
|
||||||
|
names:append(pnames[i])
|
||||||
|
comments:append(pcomments[i] or '')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,5 +8,7 @@ This description applies to the project as a whole.
|
||||||
|
|
||||||
alias("p","param")
|
alias("p","param")
|
||||||
|
|
||||||
|
file = {'mod1.lua','modtest.lua','mylib.c'}
|
||||||
|
|
||||||
new_type("macro","Macros")
|
new_type("macro","Macros")
|
||||||
|
|
||||||
|
|
|
@ -57,4 +57,25 @@ function mod1.zero_function(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-------
|
||||||
|
-- Multiple params may match a varargs function.
|
||||||
|
-- Generally, ldoc tries to be strict about matching params and formal arguments,
|
||||||
|
-- but this is relaxed for varargs: `function other(p,...)`
|
||||||
|
-- @param p
|
||||||
|
-- @param q
|
||||||
|
-- @param r
|
||||||
|
function mod1.other(p,...)
|
||||||
|
-- something cunning with select(2,...)
|
||||||
|
end
|
||||||
|
|
||||||
|
-------
|
||||||
|
-- A function with typed arguments.
|
||||||
|
-- The tparam tag is followed by the 'type'. There is no standard way
|
||||||
|
-- to represent Lua types, but you can adopt a convention. Type names
|
||||||
|
-- will be resolved. treturn must include a description after the type.
|
||||||
|
-- @tparam string name
|
||||||
|
-- @tparam number age
|
||||||
|
-- @treturn string modified age
|
||||||
|
function mod1.typed(name,age)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -3,7 +3,16 @@
|
||||||
-- Scripts are not containers in the sense that modules are,
|
-- Scripts are not containers in the sense that modules are,
|
||||||
-- (although perhaps the idea of 'commands' could be adopted for some utilities)
|
-- (although perhaps the idea of 'commands' could be adopted for some utilities)
|
||||||
-- It allows any upfront script comments to be included in the
|
-- It allows any upfront script comments to be included in the
|
||||||
-- documentation.
|
-- documentation. Any long string marked with the 'usage' tag will also appear
|
||||||
|
-- in this area.
|
||||||
|
--
|
||||||
-- @script modtest
|
-- @script modtest
|
||||||
|
|
||||||
print 'hello, world'
|
--- @usage
|
||||||
|
local usage = [[
|
||||||
|
modtest NAME
|
||||||
|
where NAME is your favourite name!
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
|
print ('hello',arg[1])
|
||||||
|
|
Loading…
Reference in New Issue