mirror of https://github.com/Hilbis/Hilbish
docs: add more details to module docs
parent
e8e75ab27b
commit
dfc3942087
34
module.go
34
module.go
|
@ -11,21 +11,39 @@ import (
|
||||||
// #interface module
|
// #interface module
|
||||||
// native module loading
|
// native module loading
|
||||||
// #field paths A list of paths to search when loading native modules. This is in the style of Lua search paths and will be used when requiring native modules. Example: `?.so;?/?.so`
|
// #field paths A list of paths to search when loading native modules. This is in the style of Lua search paths and will be used when requiring native modules. Example: `?.so;?/?.so`
|
||||||
/* The hilbish.module interface provides a function
|
/* The hilbish.module interface provides a function to load
|
||||||
to load Hilbish plugins/modules.
|
Hilbish plugins/modules. Hilbish modules are Go-written
|
||||||
Hilbish modules are Go-written plugins (see https://pkg.go.dev/plugin)
|
plugins (see https://pkg.go.dev/plugin) that are used to add functionality
|
||||||
that are used to add functionality to Hilbish that cannot be written
|
to Hilbish that cannot be written in Lua for any reason.
|
||||||
in Lua for any reason.
|
|
||||||
|
|
||||||
To make a valid native module, the Go plugin
|
Note that you don't ever need to use the load function that is here as
|
||||||
has to export a Loader function with a signature like so:
|
modules can be loaded with a `require` call like Lua C modules, and the
|
||||||
`func(*rt.Runtime) rt.Value`.
|
search paths can be changed with the `paths` property here.
|
||||||
|
|
||||||
|
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
|
`rt` in this case refers to the Runtime type at
|
||||||
https://pkg.go.dev/github.com/arnodel/golua@master/runtime#Runtime
|
https://pkg.go.dev/github.com/arnodel/golua@master/runtime#Runtime
|
||||||
|
|
||||||
Hilbish uses this package as its Lua runtime. You will need to read
|
Hilbish uses this package as its Lua runtime. You will need to read
|
||||||
it to use it for a native plugin.
|
it to use it for a native plugin.
|
||||||
|
|
||||||
|
Here is some code for an example plugin:
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
rt "github.com/arnodel/golua/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Loader(rtm *rt.Runtime) rt.Value {
|
||||||
|
return rt.StringValue("hello world!")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This can be compiled with `go build -buildmode=plugin plugin.go`.
|
||||||
|
If you attempt to require and print the result (`print(require 'plugin')`), it will show "hello world!"
|
||||||
*/
|
*/
|
||||||
func moduleLoader(rtm *rt.Runtime) *rt.Table {
|
func moduleLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
exports := map[string]util.LuaExport{
|
exports := map[string]util.LuaExport{
|
||||||
|
|
Loading…
Reference in New Issue