lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2013/3/23 Dirk Laurie <dirk.laurie@gmail.com>:
> 2013/3/23 oliver <oliver.schoenborn@gmail.com>:
>> I'm going to need something like this in bluash (on github). Did you just
>> "whip this up" or is it part of a project I can "require" from bluash?

It's available from:

   https://github.com/dlaurie/lua-ihelp

I've turned it into a one-file module coded in Lua. You save it
somewhere in your file path under a name of your own choosing.
Say you have called it "help.lua". Then use it as follows:

---------------------------

$lua
Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> help=require"help"
> help()

The following functions are provided:
   help
Try `help"topic"`, e.g. help"all", or `help(function)`, e.g. `help(help)`.

> help(help)

---    help(fct)
-- none: Prints short help.
-- function: Prints the docstring of `fct`, if any.
-- table: Prints `help` field, if any; else contents.
-- string: Prints help on the topic, if any.
-- "all": Prints available topics.

> help"all"
Help available via `help"topic"` on these topics:
  bugs customize docstring method

> help"customize"

After `help(arg,msg)`, where `arg` is nil or any string except `all`,
the message you get when typing `help(arg)` will be `msg`.

> help"docstring"
---    The docstring of a function
-- A comment block from the Lua code of a function, formatted in LDoc
-- style, like this block. The comments may come immediately before the
-- first line of the function or anywhere inside it.  All comments must
-- start at position 1 of their lines and the first comment must start
-- with at least three hyphens. For a very short function, the whole
-- code is used as the docstring.
--
-- Not available for functions defined from the terminal while running
-- the standalone Lua interpreter.

> help("customize",nil)
> help"customize"
Don't know how to find help for customize

> help(nil,"Have a nice day!")
> help()
Have a nice day!

-------------------------------------

Comments not welcome. I'm not maintaining this except when there
is a definite bug. That's why it's on GitHub. Fork the repository,
implement your own ideas, announce your version here. If people
like it better than this one, nobody will be better pleased than me.

Enjoy!

Dirk