From 7786b4f37a81db3185e0709003bfcc8b2854d126 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 30 Mar 2022 20:11:15 -0400 Subject: [PATCH] feat: add module description docs --- api.go | 17 +++++++++-------- golibs/bait/bait.go | 4 +--- golibs/commander/commander.go | 2 +- golibs/fs/fs.go | 4 +--- golibs/terminal/terminal.go | 2 +- util/util.go | 17 ++++++++--------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/api.go b/api.go index 20b40a7..43c27a9 100644 --- a/api.go +++ b/api.go @@ -76,14 +76,14 @@ Check out the {blue}{bold}guide{reset} command to get started. util.SetField(rtm, mod, "greeting", rt.StringValue(greeting), "Hilbish's welcome message for interactive shells. It has Lunacolors formatting.") util.SetField(rtm, mod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)") util.SetField(rtm, hshMod, "exitCode", rt.IntValue(0), "Exit code of last exected command") - //util.Document(rtm, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.") + util.Document(mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.") // hilbish.userDir table hshuser := rt.NewTable() util.SetField(rtm, hshuser, "config", rt.StringValue(confDir), "User's config directory") util.SetField(rtm, hshuser, "data", rt.StringValue(userDataDir), "XDG data directory") - //util.Document(rtm, hshuser, "User directories to store configs and/or modules.") + util.Document(hshuser, "User directories to store configs and/or modules.") mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser)) /* @@ -101,35 +101,36 @@ Check out the {blue}{bold}guide{reset} command to get started. // hilbish.aliases table aliases = newAliases() aliasesModule := aliases.Loader(rtm) - //util.Document(L, aliasesModule, "Alias inferface for Hilbish.") + util.Document(aliasesModule, "Alias inferface for Hilbish.") mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule)) // hilbish.history table historyModule := lr.Loader(rtm) - //util.Document(L, historyModule, "History interface for Hilbish.") mod.Set(rt.StringValue("history"), rt.TableValue(historyModule)) + util.Document(historyModule, "History interface for Hilbish.") // hilbish.completion table hshcomp := rt.NewTable() - util.SetField(rtm, hshcomp, "files", rt.FunctionValue(rt.NewGoFunction(luaFileComplete, "files", 3, false)), "Completer for files") + util.SetField(rtm, hshcomp, "bins", rt.FunctionValue(rt.NewGoFunction(luaBinaryComplete, "bins", 3, false)), "Completer for executables/binaries") - //util.Document(L, hshcomp, "Completions interface for Hilbish.") + + util.Document(hshcomp, "Completions interface for Hilbish.") mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp)) // hilbish.runner table runnerModule := runnerModeLoader(rtm) - //util.Document(L, runnerModule, "Runner/exec interface for Hilbish.") + util.Document(runnerModule, "Runner/exec interface for Hilbish.") mod.Set(rt.StringValue("runner"), rt.TableValue(runnerModule)) // hilbish.jobs table jobs = newJobHandler() jobModule := jobs.loader(rtm) -// util.Document(L, jobModule, "(Background) job interface.") + util.Document(jobModule, "(Background) job interface.") mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule)) return rt.TableValue(mod), nil diff --git a/golibs/bait/bait.go b/golibs/bait/bait.go index 3380470..3112903 100644 --- a/golibs/bait/bait.go +++ b/golibs/bait/bait.go @@ -40,8 +40,7 @@ func (b *Bait) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { mod := rt.NewTable() util.SetExports(rtm, mod, exports) -/* - util.Document(L, mod, + util.Document(mod, `Bait is the event emitter for Hilbish. Why name it bait? Because it throws hooks that you can catch (emits events that you can listen to) and because why not, fun naming @@ -49,7 +48,6 @@ is fun. This is what you will use if you want to listen in on hooks to know when certain things have happened, like when you've changed directory, a command has failed, etc. To find all available hooks, see doc hooks.`) -*/ return rt.TableValue(mod), nil } diff --git a/golibs/commander/commander.go b/golibs/commander/commander.go index 204e108..d279e0c 100644 --- a/golibs/commander/commander.go +++ b/golibs/commander/commander.go @@ -32,7 +32,7 @@ func (c *Commander) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { } mod := rt.NewTable() util.SetExports(rtm, mod, exports) -// util.Document(L, mod, "Commander is Hilbish's custom command library, a way to write commands in Lua.") + util.Document(mod, "Commander is Hilbish's custom command library, a way to write commands in Lua.") return rt.TableValue(mod), nil } diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 4cede57..042f2a8 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -26,11 +26,9 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { mod := rt.NewTable() util.SetExports(rtm, mod, exports) -/* - util.Document(L, mod, `The fs module provides easy and simple access to + util.Document(mod, `The fs module provides easy and simple access to filesystem functions and other things, and acts an addition to the Lua standard library's I/O and fs functions.`) -*/ return rt.TableValue(mod), nil } diff --git a/golibs/terminal/terminal.go b/golibs/terminal/terminal.go index 614bebe..df1755c 100644 --- a/golibs/terminal/terminal.go +++ b/golibs/terminal/terminal.go @@ -26,7 +26,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { mod := rt.NewTable() util.SetExports(rtm, mod, exports) - //util.Document(L, mod, "The terminal library is a simple and lower level library for certain terminal interactions.") + util.Document(mod, "The terminal library is a simple and lower level library for certain terminal interactions.") return rt.TableValue(mod), nil } diff --git a/util/util.go b/util/util.go index 5534f0d..8a58262 100644 --- a/util/util.go +++ b/util/util.go @@ -3,21 +3,20 @@ package util import ( "os" - "github.com/yuin/gopher-lua" rt "github.com/arnodel/golua/runtime" ) // Document adds a documentation string to a module. // It is accessible via the __doc metatable. -func Document(L *lua.LState, module lua.LValue, doc string) { -/* - mt := L.GetMetatable(module) - if mt == lua.LNil { - mt = L.NewTable() - L.SetMetatable(module, mt) +func Document(module *rt.Table, doc string) { + mt := module.Metatable() + + if mt == nil { + mt = rt.NewTable() + module.SetMetatable(mt) } - L.SetField(mt, "__doc", lua.LString(doc)) -*/ + + mt.Set(rt.StringValue("__doc"), rt.StringValue(doc)) } // SetField sets a field in a table, adding docs for it.