On Thu, Feb 19, 2004 at 02:19:47PM +0100, Stefan ReichÃr wrote:
> Another question: is it possible in lua to add a function comment?
> This comment could be shown, when describe-key is invoked.
> It would be nice to see a self-documenting ion with an emacs-like help system.

mkexports.lua can parse the documentation comments from .lua and .c 
files and it could be modified to generate a help file. 

Alternatively one could define something like (untested)

local docu={}

function defun(fname, doc, func, noset)
    local t=_G;
    -- Find table to put in
    local nm=string.gsub(fname, "([^.]*)%.",
                         function(tname)
                             assert(t~="")
                             assert(t[tname])
                             t=t[tname]
                         end)
    if not noset then
        t[nm]=func
    end
    docu[func]=doc
    docu[fname]=doc
end

function descfun(func_or_name)
    return docu[func_or_name]
end

Then to define a function:

defun("libfoobar.do_foobar",
      "This function does something totally useless.",
      function(param)
          -- do something totally useless
      end)

And auto-generate for the C side stuff code as follows:

defun("ioncore.foobar",
      "Just documentation for C side stuff",
      ioncore.foobar,
      true)


But... you can't directly descfun(binding_str), because the bindings
still have Lua code in them instead of just the name of a function,
and may (in theory) call multiple functions or not even contain the
name of a documented as the first [a-zA-Z_.]* string before a 
parenthesis. But one could always try to decipher it...
(See my another post for some talk on the new binding scheme.)

-- 
Tuomo

Reply via email to