Documentation
¶
Index ¶
- func ConvertToLua(L *lua.LState, v interface{}) lua.LValue
- func MapToLuaTable(L *lua.LState, m map[string]interface{}) *lua.LTable
- func NewSandboxedVM() *lua.LState
- func SliceToLuaTable(L *lua.LState, arr []interface{}) *lua.LTable
- type ExecutionRecorder
- type ExecutionResult
- type ExecutionStatus
- type Executor
- type ExecutorConfig
- type HostFunctionRegistry
- type Script
- type WorkerPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToLua ¶
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 ¶
MapToLuaTable converts a Go map[string]interface{} to a Lua table.
func NewSandboxedVM ¶
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.
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 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.