plugin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterBridge

func RegisterBridge(sb *Sandbox)

RegisterBridge registers all Go bridge modules (fs, http, json, sleep, log) into the sandbox.

Types

type Manager

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

Manager manages Lua plugin loading, subscribe, and publish lifecycle.

func NewManager

func NewManager(logger *slog.Logger) *Manager

NewManager creates a new plugin manager.

func (*Manager) Close

func (m *Manager) Close() error

Close shuts down all plugin Lua states.

func (*Manager) HasPlugin

func (m *Manager) HasPlugin(name string) bool

HasPlugin returns true if a plugin with the given name is loaded.

func (*Manager) IsPlugin

func (m *Manager) IsPlugin(name string) bool

IsPlugin is an alias for HasPlugin, used by the runner to distinguish plugins from Athyr topics.

func (*Manager) LoadPlugin

func (m *Manager) LoadPlugin(cfg config.PluginConfig) error

LoadPlugin creates a sandbox, loads the Lua file, and registers bridge modules.

func (*Manager) Publish

func (m *Manager) Publish(name string, data string) error

Publish calls the plugin's Lua publish(config, data) function synchronously.

func (*Manager) StartSubscribe

func (m *Manager) StartSubscribe(name string, callback func(string)) error

StartSubscribe calls the plugin's Lua subscribe(config, callback) function in a goroutine.

type Sandbox

type Sandbox struct {
	L *lua.LState
	// contains filtered or unexported fields
}

Sandbox wraps a Lua state with restricted library access.

func NewSandbox

func NewSandbox(restrict []string) (*Sandbox, error)

NewSandbox creates a sandboxed Lua state. restrict is a list of API names to block (e.g., "fs", "http.post"). Pass nil for no restrictions.

func (*Sandbox) Close

func (s *Sandbox) Close()

Close shuts down the Lua state.

func (*Sandbox) DoFile

func (s *Sandbox) DoFile(path string) error

DoFile executes a Lua file.

func (*Sandbox) DoString

func (s *Sandbox) DoString(code string) error

DoString executes a Lua string.

func (*Sandbox) IsRestricted

func (s *Sandbox) IsRestricted(api string) bool

IsRestricted checks if a given API call is blocked by the restriction list. Supports both module-level ("fs") and function-level ("fs.write") restrictions.

Jump to

Keyboard shortcuts

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