Documentation
¶
Index ¶
- Variables
- type Instance
- func (inst *Instance) Do(m *Manager, id uuid.UUID, action VMAction) error
- func (inst *Instance) IsBusy() bool
- func (inst *Instance) RegisterFunction(name string, fn lua.LGFunction)
- func (inst *Instance) RegisterFunctions(functions map[string]lua.LGFunction)
- func (inst *Instance) RegisterGlobal(name string, value lua.LValue)
- func (inst *Instance) RegisterGlobals(globals map[string]lua.LValue)
- func (inst *Instance) RegisterModule(name string, provider ModuleProvider)
- func (inst *Instance) RegisterModules(providers map[string]ModuleProvider)
- type InstanceInfo
- type LuaInstanceModuleProvider
- type LuaSymbol
- type Manager
- func (m *Manager) Close()
- func (m *Manager) Do(id uuid.UUID, action VMAction) error
- func (m *Manager) GetInstance(id uuid.UUID) (*Instance, error)
- func (m *Manager) InstanceInfo(id uuid.UUID) (InstanceInfo, error)
- func (m *Manager) PrepareModuleProviderVM(config ModuleProviderVMConfig) (uuid.UUID, *Instance, error)
- func (m *Manager) PrepareVM(mode VMMode, persistent bool, code string) (uuid.UUID, *Instance, error)
- func (m *Manager) RegisterFunction(name string, fn lua.LGFunction)
- func (m *Manager) RegisterFunctions(functions map[string]lua.LGFunction)
- func (m *Manager) RegisterGlobal(name string, value lua.LValue)
- func (m *Manager) RegisterGlobals(globals map[string]lua.LValue)
- func (m *Manager) RegisterInstanceFunction(id uuid.UUID, name string, fn lua.LGFunction)
- func (m *Manager) RegisterInstanceFunctions(id uuid.UUID, functions map[string]lua.LGFunction)
- func (m *Manager) RegisterInstanceGlobal(id uuid.UUID, name string, value lua.LValue)
- func (m *Manager) RegisterInstanceGlobals(id uuid.UUID, globals map[string]lua.LValue)
- func (m *Manager) RegisterInstanceModule(id uuid.UUID, name string, provider ModuleProvider)
- func (m *Manager) RegisterInstanceModules(id uuid.UUID, providers map[string]ModuleProvider)
- func (m *Manager) RegisterModule(name string, provider ModuleProvider)
- func (m *Manager) RegisterModules(providers map[string]ModuleProvider)
- func (m *Manager) SetDefaultSender(sender string)
- type ModuleContext
- type ModuleProvider
- type ModuleProviderFunc
- type ModuleProviderVMConfig
- type VMAction
- type VMMode
Constants ¶
This section is empty.
Variables ¶
var ( ErrInstanceNotFound = errors.New("scripting: instance not found") ErrInstanceBusy = errors.New("scripting: instance is locked") ErrInstancePaused = errors.New("scripting: instance is paused") ErrInstanceKilled = errors.New("scripting: instance is killed") )
Manager level errors to aid callers when coordinating VM access.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance stores metadata and synchronization primitives for a compiled Lua VM.
func (*Instance) Do ¶ added in v0.12.8
Do executes the requested VM action for this instance.
func (*Instance) IsBusy ¶ added in v0.12.8
IsBusy reports whether the instance lock is currently held.
func (*Instance) RegisterFunction ¶ added in v0.12.8
func (inst *Instance) RegisterFunction(name string, fn lua.LGFunction)
RegisterFunction attaches an instance-scoped helper callable from Lua.
func (*Instance) RegisterFunctions ¶ added in v0.12.18
func (inst *Instance) RegisterFunctions(functions map[string]lua.LGFunction)
RegisterFunctions attaches instance-scoped helpers callable from Lua.
func (*Instance) RegisterGlobal ¶ added in v0.12.8
RegisterGlobal exposes an instance-scoped global Lua value.
func (*Instance) RegisterGlobals ¶ added in v0.12.18
RegisterGlobals exposes instance-scoped global Lua values.
func (*Instance) RegisterModule ¶ added in v0.12.18
func (inst *Instance) RegisterModule(name string, provider ModuleProvider)
RegisterModule applies an instance-scoped provider for a single module.
func (*Instance) RegisterModules ¶ added in v0.12.18
func (inst *Instance) RegisterModules(providers map[string]ModuleProvider)
RegisterModules applies instance-scoped module provider overrides/extensions.
type InstanceInfo ¶ added in v0.12.4
InstanceInfo reports metadata about a tracked VM instance.
type LuaInstanceModuleProvider ¶ added in v0.12.18
type LuaInstanceModuleProvider struct {
InstanceID uuid.UUID
ExportFunction string
InvokeFunction string
// contains filtered or unexported fields
}
LuaInstanceModuleProvider resolves modules through another managed Lua VM. The provider VM must be persistent and expose export/invoke globals.
func NewLuaInstanceModuleProvider ¶ added in v0.12.18
func NewLuaInstanceModuleProvider(instanceID uuid.UUID, exportFunction, invokeFunction string) *LuaInstanceModuleProvider
NewLuaInstanceModuleProvider builds a provider backed by another VM instance.
func (*LuaInstanceModuleProvider) ProvideModule ¶ added in v0.12.18
func (p *LuaInstanceModuleProvider) ProvideModule(ctx *ModuleContext) (lua.LValue, error)
ProvideModule resolves a module by invoking export logic inside the provider VM.
type LuaSymbol ¶ added in v0.12.18
type LuaSymbol struct {
// Value exports a literal Lua value as module[field].
Value lua.LValue
// Function exports a Go callback as module[field] when non-nil.
Function lua.LGFunction
}
LuaSymbol describes a field exported from a Go-defined Lua module table.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates multiple sandboxed Lua states.
func NewManager ¶
NewManager creates a manager with an optional logger. When logger is nil, scripting logs are dropped.
func (*Manager) Close ¶
func (m *Manager) Close()
Close stops all persistent instances managed by this manager.
func (*Manager) Do ¶ added in v0.12.4
Do performs an action against a persistent VM identified by id.
func (*Manager) GetInstance ¶ added in v0.12.6
GetInstance retrieves a tracked VM instance by ID.
func (*Manager) InstanceInfo ¶ added in v0.12.4
func (m *Manager) InstanceInfo(id uuid.UUID) (InstanceInfo, error)
InstanceInfo returns metadata for the VM identified by id.
func (*Manager) PrepareModuleProviderVM ¶ added in v0.12.18
func (m *Manager) PrepareModuleProviderVM(config ModuleProviderVMConfig) (uuid.UUID, *Instance, error)
PrepareModuleProviderVM prepares a persistent VM meant to back module providers.
func (*Manager) PrepareVM ¶ added in v0.12.8
func (m *Manager) PrepareVM(mode VMMode, persistent bool, code string) (uuid.UUID, *Instance, error)
PrepareVM compiles the provided script and stores it for future execution. Persistent VMs remain tracked and can be controlled via Do; volatile ones run once after calling Run. Every VM receives a UUIDv7 identifier.
func (*Manager) RegisterFunction ¶
func (m *Manager) RegisterFunction(name string, fn lua.LGFunction)
RegisterFunction exposes a Go function to all future Lua states managed by this manager.
func (*Manager) RegisterFunctions ¶ added in v0.12.18
func (m *Manager) RegisterFunctions(functions map[string]lua.LGFunction)
RegisterFunctions exposes Go functions to all future Lua states managed by this manager.
func (*Manager) RegisterGlobal ¶ added in v0.12.4
RegisterGlobal exposes a Go value to all future Lua states managed by this manager.
func (*Manager) RegisterGlobals ¶ added in v0.12.18
RegisterGlobals exposes Go values to all future Lua states managed by this manager.
func (*Manager) RegisterInstanceFunction ¶ added in v0.12.6
RegisterInstanceFunction attaches a helper to a specific VM.
func (*Manager) RegisterInstanceFunctions ¶ added in v0.12.18
RegisterInstanceFunctions attaches multiple helpers to a specific VM.
func (*Manager) RegisterInstanceGlobal ¶ added in v0.12.6
RegisterInstanceGlobal provides an instance-scoped global Lua value.
func (*Manager) RegisterInstanceGlobals ¶ added in v0.12.18
RegisterInstanceGlobals provides instance-scoped global Lua values.
func (*Manager) RegisterInstanceModule ¶ added in v0.12.18
func (m *Manager) RegisterInstanceModule(id uuid.UUID, name string, provider ModuleProvider)
RegisterInstanceModule registers a VM-specific provider for a single module.
func (*Manager) RegisterInstanceModules ¶ added in v0.12.18
func (m *Manager) RegisterInstanceModules(id uuid.UUID, providers map[string]ModuleProvider)
RegisterInstanceModules applies VM-specific module provider overrides/extensions.
func (*Manager) RegisterModule ¶ added in v0.12.18
func (m *Manager) RegisterModule(name string, provider ModuleProvider)
RegisterModule registers a manager-wide provider for a single module.
func (*Manager) RegisterModules ¶ added in v0.12.18
func (m *Manager) RegisterModules(providers map[string]ModuleProvider)
RegisterModules registers manager-wide module providers using module-name keys. Existing VMs are not backfilled; only newly prepared instances receive these bindings.
type ModuleContext ¶ added in v0.12.18
type ModuleContext struct {
Manager *Manager
Identifier string
Mode VMMode
State *lua.LState
Module string
}
ModuleContext carries metadata for resolving a single require("module") request.
type ModuleProvider ¶ added in v0.12.18
type ModuleProvider interface {
ProvideModule(ctx *ModuleContext) (lua.LValue, error)
}
ModuleProvider resolves a single module binding into a Lua value.
func GoModule ¶ added in v0.12.18
func GoModule(symbols map[string]LuaSymbol) ModuleProvider
GoModule returns a ModuleProvider that materializes a table from Go symbols.
type ModuleProviderFunc ¶ added in v0.12.18
type ModuleProviderFunc func(ctx *ModuleContext) (lua.LValue, error)
ModuleProviderFunc adapts a function into a ModuleProvider.
func (ModuleProviderFunc) ProvideModule ¶ added in v0.12.18
func (f ModuleProviderFunc) ProvideModule(ctx *ModuleContext) (lua.LValue, error)
ProvideModule satisfies ModuleProvider.
type ModuleProviderVMConfig ¶ added in v0.12.18
type ModuleProviderVMConfig struct {
Mode VMMode
Code string
Functions map[string]lua.LGFunction
Globals map[string]lua.LValue
Modules map[string]ModuleProvider
}
ModuleProviderVMConfig configures a persistent Lua VM intended to serve modules.
type VMAction ¶ added in v0.12.4
type VMAction uint8
VMAction enumerates supported manager operations for persistent VMs.
const ( // Run executes the compiled script, blocking until the VM lock is held. Run VMAction = iota // RunSafe only executes when TryLock succeeds and otherwise returns ErrInstanceBusy. RunSafe // Terminate waits for the current run to finish, then removes the VM cleanly. Terminate // Kill forcibly removes the VM immediately without waiting for the run to finish. Kill )
type VMMode ¶ added in v0.12.2
type VMMode uint8
const ( // Sandboxed removes risky loaders and keeps require() restricted to registered modules. Sandboxed VMMode = iota // Elevated exposes os/io/package helpers while still skipping arbitrary C loading. Elevated // Unsafe opens the full set of Lua libs for debugging/compatibility scenarios. Unsafe )
Source Files
¶
- instance.go
- manager.go
- modules.go