gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/help.lua
diff options
context:
space:
mode:
Diffstat (limited to 'help.lua')
-rw-r--r--help.lua 27
1 files changed, 21 insertions, 6 deletions
diff --git a/help.lua b/help.lua
index 9346ccab..02fd8b08 100644
--- a/help.lua
+++ b/help.lua
@@ -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
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月17日 09:15:22 +0000

AltStyle によって変換されたページ (->オリジナル) /