Like many "(windows) users" I do not want to spend time learning to compile anything from source.
So Lua seems a very good choice for a hobbyist.
Sorry if this is a very simple problem - but...
Q1. How can I list the modules available to any given instance of the interpreter?
Some binary distros have a number of modules compiled as DLLs, and some have them added into the main EXE.
It would be nice to know which modules are built in to the EXE, and check the cpath is finding any other DLL modules.
Q2. Is there a way to get help at the command line in Lua?
As I am new to Lua I would like an easy way to get help for any given function.
In some interpreted languages there is a help("fname") function, Matlab is a good example.
Q3. Could this function from GSL-Shell be modified as a basis for a help system?
(Even if it just confirmed the existence of a given function it would help)
local ffi = require 'ffi'
local help_files = {'graphics', 'matrix', 'iter', 'integ', 'ode', 'nlfit', 'vegas', 'rng', 'fft'}
local cdata_table = {'matrix', 'complex matrix', 'complex'}
local function help_init( ... )
local REG = debug.getregistry()
REG['GSL.help_hook'] = {}
end
local function open_module(modname)
local fullname = string.format('help/%s', modname)
local m = require(fullname)
return m
end
local function search_help(func)
for k, modname in ipairs(help_files) do
local mt = getmetatable(func)
local module = open_module(modname)
if module[func] then
local help_text = module[func]
return help_text
end
end
end
help_init()
-- declare a global function
function help(x)
local txt
if type(x) == 'function' then
txt = search_help(x)
elseif type(x) == 'userdata' then
local mt = getmetatable(x)
if mt then txt = search_help(mt) end
elseif type(x) == 'cdata' then
local cname = gsl_type(x)
if cname then txt = search_help(cname) end
end
--- Could we check that the function exists?
print(txt or "No help found for the given function")
end