luart

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package luart provides a pure-Go Lua 5.1 implementation of script.Runtime using github.com/yuin/gopher-lua (no CGO).

Index

Constants

This section is empty.

Variables

View Source
var ErrRuntimeClosed = errors.New("luart: runtime is closed")

ErrRuntimeClosed is returned when Exec is called after Close.

View Source
var ErrVMPoolBusy = errdefs.NotAvailable(errors.New("luart: VM pool exhausted"))

ErrVMPoolBusy is returned by nested execution when no LState is immediately available. Nested scripts must not wait on the same pool their parent holds.

View Source
var ErrVMPoolExhausted = errdefs.NotAvailable(errors.New("luart: VM pool exhausted, context cancelled while waiting"))

ErrVMPoolExhausted is returned when all VMs are in use and the context is cancelled before one becomes available.

Functions

This section is empty.

Types

type Option

type Option func(*Runtime)

Option configures a Runtime.

func WithMaxExecTime added in v0.2.6

func WithMaxExecTime(d time.Duration) Option

WithMaxExecTime sets a runtime-enforced wall-clock ceiling on each Exec call. Independent of the caller's context: even ctx.Background cannot exceed d. The shorter of (caller deadline, d) wins. Zero disables the cap.

On expiry the script is interrupted via gopher-lua's context hook and Exec returns a context-deadline error classified by sdk/errdefs.IsTimeout.

func WithPoolSize

func WithPoolSize(n int) Option

WithPoolSize sets the VM pool size.

type Runtime

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

Runtime manages a pool of gopher-lua VMs for Lua script execution. It implements script.Runtime. Close is safe to call multiple times.

Note on memory caps: gopher-lua exposes no safe memory or instruction-count quota (its SetMx hook calls os.Exit on overflow, which is unusable in a library). The wall-clock ceiling installed via WithMaxExecTime is therefore the only "hard cut" available today; for stronger isolation run the script under a separate OS process with cgroup/rlimit applied.

func New

func New(opts ...Option) *Runtime

New creates a new Lua runtime with a VM pool.

func (*Runtime) Close

func (r *Runtime) Close() error

Close drains the VM pool and closes every LState. It is safe to call multiple times; subsequent calls are no-ops.

func (*Runtime) Exec

func (r *Runtime) Exec(ctx context.Context, name, source string, env *script.Env) (*script.Signal, error)

Exec implements script.Runtime. It runs Lua in a pooled LState with config and bindings as globals. A built-in "signal" global is always injected for interrupt/error/done control flow back to the host.

func (*Runtime) ExecNested added in v0.4.5

func (r *Runtime) ExecNested(ctx context.Context, name, source string, env *script.Env) (*script.Signal, error)

ExecNested runs a child script only when another LState is immediately available. It is used by runtime.execScript to avoid parent scripts deadlocking each other while they still hold their own LStates.

func (*Runtime) SupportsNestedExec added in v0.4.5

func (r *Runtime) SupportsNestedExec() bool

SupportsNestedExec reports whether runtime.execScript has any chance of acquiring a second LState while a parent script is still holding one. Runtime bindings still use ExecNested so they can fail fast when busy.

Jump to

Keyboard shortcuts

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