lua-users home
lua-l archive

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


2013/3/12 steve donovan <steve.j.donovan@gmail.com>:


> On a slight tangent, it comes up occasionally, especially
> from former Python users like Dirk,

Will I never live that down? Please emphasize _former_.

> that it would be very useful to have interactive help for
> modules.

I have started doing this: the C function that loads the module
does a "luaL_dostring" on a Lua script with the following text:

~~~
char *mymodule_init =
"print "
"'Welcome to the mymodule library! The following functions are available:'"
"local contents={} "
"for k in pairs(tuple) do contents[#contents+1]=k end "
"table.sort(contents); print(table.concat(contents,'  ')) "
;
~~~

As often as not "help" will feature among those functions.

If I don't want that message to appear, I do this:

~~~
keep = print
print = function() return end
mymodule = require "mymodule" end
print = keep
~~~