像许多“( windows)用户”一样,我不想花时间学习从源代码编译任何东西. 所以Lua似乎是一个业余爱好者的非常好的选择. 对不起,如果这是一个非常简单的问题 – 但…… Q1.如何列出任何给
所以Lua似乎是一个业余爱好者的非常好的选择.
对不起,如果这是一个非常简单的问题 – 但……
Q1.如何列出任何给定解释器实例可用的模块?
一些二进制发行版有许多编译为DLL的模块,有些已将它们添加到主EXE中.
很高兴知道哪些模块内置在EXE中,并检查cpath是否正在查找任何其他DLL模块.
Q2.有没有办法在Lua的命令行获得帮助?
由于我是Lua的新手,我想要一个简单的方法来获得任何给定功能的帮助.
在一些解释语言中有一个帮助(“fname”)函数,Matlab就是一个很好的例子.
Q3.可以将GSL-Shell的此功能修改为帮助系统的基础吗?
(即使它只是确认了某个给定函数的存在,它会有所帮助)
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
Q2:没有任何标准的帮助功能.已经有一些努力来标准化文档格式,但据我所知,它们都没有得到太大的牵引力.
问题3:假设您已正确设置帮助文件,该功能当然可以用作帮助系统的基础.
话虽如此,如果您只是想知道给定模块中可用的功能,通常只需转储模块表并查找即可.以lua演示中的globals example为例.
