author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年11月18日 23:05:33 +0100 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年11月18日 23:05:33 +0100 |
commit | 7e009c558a0c1516c6908885ac97731e4ab962e9 (patch) | |
tree | edf3367c3ee643404a91c0cb32d032133a824bf2 /help.lua | |
parent | 1d426850617c2a47bc17ce2a6cbc03a08b7066e8 (diff) | |
download | gsl-shell-7e009c558a0c1516c6908885ac97731e4ab962e9.tar.gz |
-rw-r--r-- | help.lua | 27 |
@@ -1,11 +1,20 @@ +local ffi = require 'ffi' local help_files = {'graphics', 'matrix', 'iter', 'integ', 'ode', 'nlfit', 'vegas', 'rng'} +local cdata_table = {'gsl_matrix', 'gsl_matrix_complex', 'complex'} + local function help_init( ... ) local REG = debug.getregistry() REG['GSL.help_hook'] = {} end +local function cdata_name(x) + for _, name in ipairs(cdata_table) do + if ffi.istype(ffi.typeof(name), x) then return name end + end +end + local function open_module(modname) local fullname = string.format('help/%s', modname) local m = require(fullname) @@ -19,9 +28,6 @@ local function search_help(func) if module[func] then local help_text = module[func] return help_text - elseif mt and module[mt] then - local help_text = module[mt] - return help_text end end end @@ -29,7 +35,16 @@ end help_init() -- declare a global function -function help(func) - local txt = search_help(func) or "No help found for the given function" - print(txt) +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 = cdata_name(x) + if cname then txt = search_help(cname) end + end + print(txt or "No help found for the given function") end |