像许多“(Windows)用户”一样,我不想花时间学习如何从源代码编译任何东西。因此,Lua似乎是业余爱好者的一个非常好的选择。
如果这是一个非常简单的问题,我很抱歉——
Q1. 如何列出可用于任何给定解释器实例的模块?
某些二进制发行版已经编译了许多模块作为DLL,而有些则将它们添加到主EXE中。知道哪些模块内置在EXE中,并检查cpath是否找到任何其他DLL模块,会很好。
Q2. 有没有办法在Lua命令行中获得帮助?
由于我是新手,我想要一种简单的方法来获取任何给定函数的帮助。在一些解释性语言中,有一个help("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 "未找到给定函数的帮助") end