[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Microlight (was Re: paving cowpaths with libraries)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 20 Feb 2012 11:38:56 +0200
Op 20 februari 2012 11:36 schreef Dirk Laurie <dirk.laurie@gmail.com> het volgende:
9. Wrote the attached module `mldoc`.
Really attached now.
-----------------
-- help functions for Microlight
-- Dirk Laurie 2012-02-20 Licence: MIT
-- @module mldoc
local helptext = {}
local topics = {}
for line in io.popen"ldoc -m ml":lines() do
name, help = line:match"%* (.+)(%(.*)"
if name then
helptext[name]=help
table.insert(topics,name)
end
end
local ml = require "ml"
--- combine strings into lines
-- @param src A list of strings, or a string to be split
-- @param linelength The line length, defaults to 80
-- @param sep The 're' argument for ml.split, only used if src is a string
-- @return A string concatened by `\n` and a list of lines
function ml.wrap(src,linelength,sep)
linelength = linelength or 80
if type(src)=='string' then src=ml.split(src,sep) end
local i=1
local k=2
while k<=#src do
if #src[k]+#src[i]<linelength then
src[i]=src[i]..' '..src[k]
else
i=i+1; src[i]=src[k]
end
k=k+1
end
for k=i+1,#src do src[k]=nil end
return table.concat(src,'\n'), src
end
table.sort(topics)
--- gives help on `topic` or lists available topics
-- @param topic the name of a Microlight function
function ml.help(topic)
if helptext[topic] then print((ml.wrap(helptext[topic])))
else print (('-- Microlight functions --\n'..ml.wrap(topics)))
end
end
return ml.help