lua

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Lua language support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[T LuaRetTypes](script string, ops ...func(*glua.LState)) (T, error)

Run Lua Script.

Use With***() funcs to set global variables.

If WithLogger is provided, infof(...) and errorf(...) are builtin funcs that can be called inside the lua scripts for logging.

If WithLogger is not provided, you can still use infof(...), errorf(...) and printf(...), logs are written directly to stdout.

E.g., WithGlobalStr, WithGlobalNum, WithGlobalBool

func RunFile

func RunFile[T LuaRetTypes](path string, ops ...func(*glua.LState)) (T, error)

Run Lua Script File.

See Run

func RunReader

func RunReader[T LuaRetTypes](f io.Reader, ops ...func(*glua.LState)) (T, error)

Run Lua Script via Reader.

See Run

func WithGlobalBool

func WithGlobalBool(name string, v bool) func(*glua.LState)

func WithGlobalNil

func WithGlobalNil(name string) func(*glua.LState)

func WithGlobalNum

func WithGlobalNum(name string, v float64) func(*glua.LState)

func WithGlobalStr

func WithGlobalStr(name string, v string) func(*glua.LState)

func WithGlobalStrTable

func WithGlobalStrTable(name string, m map[string]any) func(*glua.LState)

Set table to global field.

Values in map must be one of the types: string, int, int8, int16, int32, int64, float32, float64, and bool; if not, the value is ignored.

func WithLogger

func WithLogger(rail Log) func(l *glua.LState)

Types

type Log

type Log interface {
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

type LuaRetTypes

type LuaRetTypes interface {
	~int | ~int32 | ~int64 | ~float32 | ~float64 | ~string | ~bool
}

Jump to

Keyboard shortcuts

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