• Subject: Re: Help function for lua
• From: Javier Guerra Giraldez <javier@...>
• Date: Thu, 16 Jan 2020 13:12:06 -0500

```On Thu, 16 Jan 2020 at 12:58, bil til <flyer31@googlemail.com> wrote:
>
> To make lua even a bit nicer for beginners, and to support nice lib
> documentation, I think it would be very nice if lua in some future
> optionally could support some function like Phyton help() in some future
> version.

untested!!:

--- help.lua
local h = {
[assert] = [=[assert (v [, message])

Issues an error when the value of its argument v is false (i.e., nil
or false); otherwise, returns all its arguments. message is an error
message; when absent, it defaults to "assertion failed!"]=],

[ipairs] = [=[ipairs (t)

Returns three values: an iterator function, the table t, and 0, so
that the construction

for i,v in ipairs(t) do body end
will iterate over the pairs (1,t[1]), (2,t[2]), ···, up to the first
integer key absent from the table.]=],

....

[coroutine.create] = [=[coroutine.create (f)

Creates a new coroutine, with body f. f must be a Lua function.
Returns this new coroutine, an object with type "thread".]=],

.....
}

return function (x)
return h[x] or "unknown "..tostring(x)
end
---  end of help.lua

use:

> help = require "help"
> help(ipairs)
ipairs (t)

Returns three values: an iterator function, the table t, and 0, so
that the construction

for i,v in ipairs(t) do body end
will iterate over the pairs (1,t[1]), (2,t[2]), ···, up to the first
integer key absent from the table.

something like this? version detection left as an exercise.  (now that
I think of it, maybe Penlight already has something similar?)

--
Javier

```