lua

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToLua

func ConvertToLua(L *lua.LState, v interface{}) lua.LValue

ConvertToLua converts a Go value to a Lua value. Supports: string, numbers (int, int32, int64, float32, float64), bool, map[string]interface{}, []interface{}, and nil. Unknown types are converted to string representation.

func MapToLuaTable

func MapToLuaTable(L *lua.LState, m map[string]interface{}) *lua.LTable

MapToLuaTable converts a Go map[string]interface{} to a Lua table.

func NewSandboxedVM

func NewSandboxedVM() *lua.LState

NewSandboxedVM creates a new Lua VM with restricted libraries for security. Only safe libraries are loaded: base, table, string, and math. Dangerous functions like os, io, debug, loadfile, dofile are disabled.

func SliceToLuaTable

func SliceToLuaTable(L *lua.LState, arr []interface{}) *lua.LTable

SliceToLuaTable converts a Go []interface{} to a Lua table. Lua arrays are 1-indexed, so the slice is converted accordingly.

Types

type ExecutionRecorder

type ExecutionRecorder interface {
	RecordExecution(ctx context.Context, result ExecutionResult) error
}

ExecutionRecorder allows recording execution results.

type ExecutionResult

type ExecutionResult struct {
	ScriptID      string
	ScriptName    string
	ScriptVersion string
	Status        ExecutionStatus
	ErrorMessage  *string
	DurationMs    int64
	ExecutedAt    time.Time
}

ExecutionResult represents the result of a script execution.

type ExecutionStatus

type ExecutionStatus string

ExecutionStatus represents the status of an execution.

const (
	ExecutionStatusSuccess ExecutionStatus = "success"
	ExecutionStatusFailure ExecutionStatus = "failure"
)

type Executor

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

Executor executes Lua scripts with timeout, error handling, and result recording.

func NewExecutor

func NewExecutor(config ExecutorConfig) *Executor

NewExecutor creates a new Lua script executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, script Script, payload map[string]interface{}) ExecutionResult

Execute executes a Lua script with the given payload. The payload is converted to a Lua table and passed to the script's "handle" function. Returns an ExecutionResult with the outcome.

type ExecutorConfig

type ExecutorConfig struct {
	Timeout       time.Duration
	Logger        *zap.Logger
	HostFunctions HostFunctionRegistry
	Recorder      ExecutionRecorder
}

ExecutorConfig holds configuration for the executor.

type HostFunctionRegistry

type HostFunctionRegistry interface {
	RegisterFunctions(L *lua.LState, scriptID, scriptName, scriptVersion string)
}

HostFunctionRegistry allows registering custom host functions for Lua scripts.

type Script

type Script interface {
	GetID() string
	GetName() string
	GetVersion() string
	GetCode() string
}

Script represents a script that can be executed.

type WorkerPool

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

WorkerPool manages concurrent execution with bounded concurrency.

func NewWorkerPool

func NewWorkerPool(maxConcurrent int) *WorkerPool

NewWorkerPool creates a new worker pool with the specified max concurrent workers. If maxConcurrent <= 0, it defaults to 10.

func (*WorkerPool) Acquire

func (p *WorkerPool) Acquire()

Acquire blocks until a worker slot is available.

func (*WorkerPool) Close

func (p *WorkerPool) Close()

Close closes the worker pool.

func (*WorkerPool) Release

func (p *WorkerPool) Release()

Release releases a worker slot.

Jump to

Keyboard shortcuts

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