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:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年08月10日 19:08:29 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年08月10日 19:08:29 +0200
commit01bfba0af03ced139c6059e484974ab8b87bcade (patch)
tree7d67bfc53d83417bdd85bb02feeaaef4697dfd32 /help.lua
parented4947f8970d96948eeed24111f6a649b011686e (diff)
downloadgsl-shell-01bfba0af03ced139c6059e484974ab8b87bcade.tar.gz
Introduce the help system for the console
The included documentation is just a small fragment of the all the available functions.
Diffstat (limited to 'help.lua')
-rw-r--r--help.lua 40
1 files changed, 40 insertions, 0 deletions
diff --git a/help.lua b/help.lua
new file mode 100644
index 00000000..c0a3b4af
--- /dev/null
+++ b/help.lua
@@ -0,0 +1,40 @@
+
+local help_files = {'graphics'}
+local help_cache = {}
+
+local function cache_function(func, help_text)
+ help_cache[func] = help_text
+end
+
+local function cache_lookup(func)
+ return help_cache[func]
+end
+
+local function open_module(modname)
+ local fullname = string.format('help/%s.lua', modname)
+ local m = dofile(fullname)
+ return m
+end
+
+local function search_help(func)
+ for k, modname in ipairs(help_files) do
+ local module = open_module(modname)
+ if module[func] then
+ local help_text = module[func]
+ cache_function(func, help_text)
+ return help_text
+ end
+ end
+end
+
+-- declare a global function
+function help(func)
+ local txt = cache_lookup(func)
+ if txt then return txt end
+ txt = search_help(func)
+ if txt then
+ echo(txt)
+ else
+ echo("Cannot find help for the given function.")
+ end
+end
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月18日 16:02:50 +0000

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