diff --git a/cmd/docgen/docgen.go b/cmd/docgen/docgen.go index aae6202..cbe6baa 100644 --- a/cmd/docgen/docgen.go +++ b/cmd/docgen/docgen.go @@ -417,7 +417,7 @@ func main() { f, _ := os.Create(docPath) f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription)) - typeTag, _ := regexp.Compile(`@\w+`) + typeTag, _ := regexp.Compile(`\B@\w+`) modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(modu.Description, "<", `\<`, -1), func(typ string) string { typName := typ[1:] typLookup := typeTable[strings.ToLower(typName)] diff --git a/docs/api/hilbish/hilbish.module.md b/docs/api/hilbish/hilbish.module.md new file mode 100644 index 0000000..5f5348e --- /dev/null +++ b/docs/api/hilbish/hilbish.module.md @@ -0,0 +1,29 @@ +--- +title: Interface hilbish.module +description: native module loading +layout: doc +menu: + docs: + parent: "API" +--- + +## Introduction + The hilbish.module interface provides a function +to load Hilbish plugins/modules. +Hilbish modules are Go-written plugins (see https://pkg.go.dev/plugin) +that are used to add functionality to Hilbish that cannot be written +n Lua for any reason. + +To make a valid native module, the Go plugin +has to export a Loader function with a signature like so: +`func(*rt.Runtime) rt.Value` +`rt` in this case refers to the Runtime type at +https://pkg.go.dev/github.com/arnodel/golua@master/runtime#Runtime +Hilbish uses this package as its Lua runtime. You will need to read +it to use it for a native plugin. + +## Functions +### load(path) +Loads a module at the designated `path`. +It will throw if any error occurs. + diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index c26c7ec..eb02a08 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -212,6 +212,10 @@ function hilbish.jobs:start() end --- Stops the job from running. function hilbish.jobs:stop() end +--- Loads a module at the designated `path`. +--- It will throw if any error occurs. +function hilbish.module.load(path) end + --- Runs a command in Hilbish's shell script interpreter. --- This is the equivalent of using `source`. --- @param cmd string diff --git a/module.go b/module.go index 6adabad..47053a5 100644 --- a/module.go +++ b/module.go @@ -8,6 +8,22 @@ import ( rt "github.com/arnodel/golua/runtime" ) +// #interface module +// native module loading +/* The hilbish.module interface provides a function +to load Hilbish plugins/modules. +Hilbish modules are Go-written plugins (see https://pkg.go.dev/plugin) +that are used to add functionality to Hilbish that cannot be written +n Lua for any reason. + +To make a valid native module, the Go plugin +has to export a Loader function with a signature like so: +`func(*rt.Runtime) rt.Value` +`rt` in this case refers to the Runtime type at +https://pkg.go.dev/github.com/arnodel/golua@master/runtime#Runtime +Hilbish uses this package as its Lua runtime. You will need to read +it to use it for a native plugin. +*/ func moduleLoader(rtm *rt.Runtime) *rt.Table { exports := map[string]util.LuaExport{ "load": {moduleLoad, 2, false}, @@ -19,6 +35,10 @@ func moduleLoader(rtm *rt.Runtime) *rt.Table { return mod } +// #interface module +// load(path) +// Loads a module at the designated `path`. +// It will throw if any error occurs. func moduleLoad(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.CheckNArgs(1); err != nil { return nil, err