feat: add module description docs

lua5.4
TorchedSammy 2022-03-30 20:11:15 -04:00
parent 14274a9432
commit 7786b4f37a
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
6 changed files with 21 additions and 25 deletions

17
api.go
View File

@ -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, "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, 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.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 // hilbish.userDir table
hshuser := rt.NewTable() hshuser := rt.NewTable()
util.SetField(rtm, hshuser, "config", rt.StringValue(confDir), "User's config directory") util.SetField(rtm, hshuser, "config", rt.StringValue(confDir), "User's config directory")
util.SetField(rtm, hshuser, "data", rt.StringValue(userDataDir), "XDG data 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)) 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 // hilbish.aliases table
aliases = newAliases() aliases = newAliases()
aliasesModule := aliases.Loader(rtm) 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)) mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule))
// hilbish.history table // hilbish.history table
historyModule := lr.Loader(rtm) historyModule := lr.Loader(rtm)
//util.Document(L, historyModule, "History interface for Hilbish.")
mod.Set(rt.StringValue("history"), rt.TableValue(historyModule)) mod.Set(rt.StringValue("history"), rt.TableValue(historyModule))
util.Document(historyModule, "History interface for Hilbish.")
// hilbish.completion table // hilbish.completion table
hshcomp := rt.NewTable() hshcomp := rt.NewTable()
util.SetField(rtm, hshcomp, "files", util.SetField(rtm, hshcomp, "files",
rt.FunctionValue(rt.NewGoFunction(luaFileComplete, "files", 3, false)), rt.FunctionValue(rt.NewGoFunction(luaFileComplete, "files", 3, false)),
"Completer for files") "Completer for files")
util.SetField(rtm, hshcomp, "bins", util.SetField(rtm, hshcomp, "bins",
rt.FunctionValue(rt.NewGoFunction(luaBinaryComplete, "bins", 3, false)), rt.FunctionValue(rt.NewGoFunction(luaBinaryComplete, "bins", 3, false)),
"Completer for executables/binaries") "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)) mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp))
// hilbish.runner table // hilbish.runner table
runnerModule := runnerModeLoader(rtm) 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)) mod.Set(rt.StringValue("runner"), rt.TableValue(runnerModule))
// hilbish.jobs table // hilbish.jobs table
jobs = newJobHandler() jobs = newJobHandler()
jobModule := jobs.loader(rtm) 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)) mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
return rt.TableValue(mod), nil return rt.TableValue(mod), nil

View File

@ -40,8 +40,7 @@ func (b *Bait) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
mod := rt.NewTable() mod := rt.NewTable()
util.SetExports(rtm, mod, exports) util.SetExports(rtm, mod, exports)
/* util.Document(mod,
util.Document(L, mod,
`Bait is the event emitter for Hilbish. Why name it bait? `Bait is the event emitter for Hilbish. Why name it bait?
Because it throws hooks that you can catch (emits events Because it throws hooks that you can catch (emits events
that you can listen to) and because why not, fun naming 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, in on hooks to know when certain things have happened,
like when you've changed directory, a command has like when you've changed directory, a command has
failed, etc. To find all available hooks, see doc hooks.`) failed, etc. To find all available hooks, see doc hooks.`)
*/
return rt.TableValue(mod), nil return rt.TableValue(mod), nil
} }

View File

@ -32,7 +32,7 @@ func (c *Commander) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
} }
mod := rt.NewTable() mod := rt.NewTable()
util.SetExports(rtm, mod, exports) 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 return rt.TableValue(mod), nil
} }

View File

@ -26,11 +26,9 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
mod := rt.NewTable() mod := rt.NewTable()
util.SetExports(rtm, mod, exports) util.SetExports(rtm, mod, exports)
/* util.Document(mod, `The fs module provides easy and simple access to
util.Document(L, mod, `The fs module provides easy and simple access to
filesystem functions and other things, and acts an filesystem functions and other things, and acts an
addition to the Lua standard library's I/O and fs functions.`) addition to the Lua standard library's I/O and fs functions.`)
*/
return rt.TableValue(mod), nil return rt.TableValue(mod), nil
} }

View File

@ -26,7 +26,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
mod := rt.NewTable() mod := rt.NewTable()
util.SetExports(rtm, mod, exports) 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 return rt.TableValue(mod), nil
} }

View File

@ -3,21 +3,20 @@ package util
import ( import (
"os" "os"
"github.com/yuin/gopher-lua"
rt "github.com/arnodel/golua/runtime" rt "github.com/arnodel/golua/runtime"
) )
// Document adds a documentation string to a module. // Document adds a documentation string to a module.
// It is accessible via the __doc metatable. // It is accessible via the __doc metatable.
func Document(L *lua.LState, module lua.LValue, doc string) { func Document(module *rt.Table, doc string) {
/* mt := module.Metatable()
mt := L.GetMetatable(module)
if mt == lua.LNil { if mt == nil {
mt = L.NewTable() mt = rt.NewTable()
L.SetMetatable(module, mt) 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. // SetField sets a field in a table, adding docs for it.