lua

package
v0.48.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package lua provides Lua-backed Hive plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandsModule

type CommandsModule struct {
	// contains filtered or unexported fields
}

CommandsModule exposes `hive.commands(map)` and accumulates registered commands. Read them out via Commands() after the entrypoint runs.

A CommandsModule is single-use: registration writes into its commands map, so create a fresh instance per Runtime.

func (*CommandsModule) Commands

func (m *CommandsModule) Commands() map[string]config.UserCommand

Commands returns the commands registered by the Lua plugin. Returns an empty map until at least one Register call has occurred.

func (*CommandsModule) Register

func (m *CommandsModule) Register(state *glua.LState, hive *glua.LTable) error

type HostModule

type HostModule interface {
	Register(state *glua.LState, hive *glua.LTable) error
}

HostModule registers part of the `hive` host API on the Lua state. Each module owns its own state and the field(s) it attaches to the hive table; adding a new API surface is "implement Register and pass an instance to NewRuntime."

type LogModule

type LogModule struct {
	PluginName string
}

LogModule exposes `hive.log.{debug,info,warn,error}` functions that emit to the standard Hive log with a "plugin" field tagged with PluginName.

func (*LogModule) Register

func (m *LogModule) Register(state *glua.LState, hive *glua.LTable) error

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin adapts a Lua entry file to Hive's plugin interface.

func New

func New(cfg config.LuaPluginConfig) *Plugin

New creates a Lua-backed Hive plugin.

func (*Plugin) Available

func (p *Plugin) Available() bool

func (*Plugin) Close

func (p *Plugin) Close() error

func (*Plugin) Commands

func (p *Plugin) Commands() map[string]config.UserCommand

func (*Plugin) Init

func (p *Plugin) Init(_ context.Context) error

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) StatusProvider

func (p *Plugin) StatusProvider() plugins.StatusProvider

type PluginInfoModule

type PluginInfoModule struct {
	Name       string
	Entry      string
	ModuleRoot string
}

PluginInfoModule exposes static metadata about the running plugin via `hive.plugin.{name,entry,module_root}`.

func (*PluginInfoModule) Register

func (m *PluginInfoModule) Register(state *glua.LState, hive *glua.LTable) error

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime owns a sandboxed Lua state for a Hive plugin. The state is private: callers interact through LoadEntrypoint / CallEntrypoint / Close.

func NewRuntime

func NewRuntime(moduleRoot string, modules ...HostModule) (*Runtime, error)

NewRuntime constructs a sandboxed Lua runtime, configures `require()` to resolve relative to moduleRoot, and registers each HostModule onto the global `hive` table in order.

func (*Runtime) CallEntrypoint

func (r *Runtime) CallEntrypoint(entrypoint *glua.LFunction) error

CallEntrypoint invokes the plugin entry function in protected mode, passing the global `hive` table as its single argument.

func (*Runtime) Close

func (r *Runtime) Close()

Close releases the underlying Lua state. Safe on a nil receiver and on a runtime that has already been closed.

func (*Runtime) LoadEntrypoint

func (r *Runtime) LoadEntrypoint(path string) (*glua.LFunction, error)

LoadEntrypoint executes the plugin entry file and returns the function it must yield as its single return value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL