像许多"(windows)用户"一样,我不想花时间学习从源代码编译任何东西.所以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
| 归档时间: |
|
| 查看次数: |
3292 次 |
| 最近记录: |