luahatch

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInstructionLimit = 1_000_000
	DefaultMemoryLimit      = 16 * 1024 * 1024
	DefaultTimeout          = 5 * time.Second
)

Variables

View Source
var (
	ErrInstructionLimit = errors.New("lua: instruction limit exceeded")
	ErrMemoryLimit      = errors.New("lua: memory limit exceeded")
	ErrTimeout          = errors.New("lua: execution timeout")
	ErrUnsafeOperation  = errors.New("lua: unsafe operation blocked")
)
View Source
var BuiltInTemplates = []LuaFilterTemplate{
	{
		Name:   "uppercase",
		Script: `return string.upper(input)`,
	},
	{
		Name:   "lowercase",
		Script: `return string.lower(input)`,
	},
	{
		Name:   "reverse",
		Script: `return string.reverse(input)`,
	},
	{
		Name:   "trim_lines",
		Script: `local lines = {} for line in input:gmatch("[^\n]+") do table.insert(lines, line:gsub("^%s*(.-)%s*$", "%1")) end return table.concat(lines, "\n")`,
	},
	{
		Name:   "remove_empty",
		Script: `local lines = {} for line in input:gmatch("[^\n]+") do if line:gsub("%s", "") ~= "" then table.insert(lines, line) end end return table.concat(lines, "\n")`,
	},
}

Functions

This section is empty.

Types

type LuaFilterTemplate

type LuaFilterTemplate struct {
	Name   string
	Script string
	Input  string
}

func GetTemplate

func GetTemplate(name string) *LuaFilterTemplate

type LuaResult

type LuaResult struct {
	Output       string
	Error        error
	Instructions int
	MemoryUsed   int
	Duration     time.Duration
}

type LuaSandbox

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

func NewLuaSandbox

func NewLuaSandbox() *LuaSandbox

func (*LuaSandbox) Execute

func (s *LuaSandbox) Execute(script string, input string) *LuaResult

Jump to

Keyboard shortcuts

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