Help us shape the future of Go! Take the 2026 Go Developer Survey

lua

package
v0.12.13 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (inst *Instance) Do(m *Manager, id uuid.UUID, action VMAction) error

Do executes the requested VM action for this instance.

func (*Instance) IsBusy added in v0.12.8

func (inst *Instance) IsBusy() bool

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) RegisterGlobal added in v0.12.8

func (inst *Instance) RegisterGlobal(name string, value lua.LValue)

RegisterGlobal exposes an instance-scoped global Lua value.

type InstanceInfo added in v0.12.4

type InstanceInfo struct {
	Mode       VMMode
	Persistent bool
	Paused     bool
	Killed     bool
	Locked     bool
}

InstanceInfo reports metadata about a tracked VM instance.

type Manager

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

Manager coordinates multiple sandboxed Lua states.

func NewManager

func NewManager(logger *log.Loggee) *Manager

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

func (m *Manager) Do(id uuid.UUID, action VMAction) error

Do performs an action against a persistent VM identified by id.

func (*Manager) GetInstance added in v0.12.6

func (m *Manager) GetInstance(id uuid.UUID) (*Instance, error)

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) 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) RegisterGlobal added in v0.12.4

func (m *Manager) RegisterGlobal(name string, value lua.LValue)

RegisterGlobal exposes a Go value to all future Lua states managed by this manager.

func (*Manager) RegisterInstanceFunction added in v0.12.6

func (m *Manager) RegisterInstanceFunction(id uuid.UUID, name string, fn lua.LGFunction)

RegisterInstanceFunction attaches a helper to a specific VM.

func (*Manager) RegisterInstanceGlobal added in v0.12.6

func (m *Manager) RegisterInstanceGlobal(id uuid.UUID, name string, value lua.LValue)

RegisterInstanceGlobal provides an instance-scoped global Lua value.

func (*Manager) SetDefaultSender

func (m *Manager) SetDefaultSender(sender string)

SetDefaultSender overrides the sender name used when logging from scripts.

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
)

func (VMAction) String added in v0.12.4

func (a VMAction) String() string

String converts the VM action to a readable representation.

type VMMode added in v0.12.2

type VMMode uint8
const (
	// Sandboxed removes risky libraries (require/load/dofile) and clears package paths.
	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
)

func (VMMode) String added in v0.12.4

func (m VMMode) String() string

String converts the VM mode to a readable representation.

Source Files

  • instance.go
  • manager.go

Jump to

Keyboard shortcuts

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