luavm

package
v0.2.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalLuaVMPool = &LuaVMPool{
	pool: sync.Pool{
		New: func() interface{} {
			L := lua.NewState()
			luajson.Preload(L)

			if len(loadedLuaFiles) > 0 {
				if err := loadPreloadedFilesToState(L); err != nil {
					slog.Error("failed to load preloaded lua files: %v", err)
				}
			}

			return L
		},
	},
}

Functions

func ExecuteLuaWithGlobalsPool added in v0.2.1

func ExecuteLuaWithGlobalsPool(f RegisterType, globals map[string]lua.LValue, source string) (lua.LValue, error)

ExecuteLuaWithGlobalsPool 使用池化的Lua虚拟机执行脚本

func LoadPreloadLuaFiles added in v0.2.2

func LoadPreloadLuaFiles(files []string) error

LoadPreloadLuaFiles 加载并验证Lua预加载文件

Types

type LuaVMPool added in v0.2.1

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

LuaVMPool Lua虚拟机池,避免全局锁竞争

func (*LuaVMPool) GetLuaState added in v0.2.1

func (p *LuaVMPool) GetLuaState() *lua.LState

GetLuaState 从池中获取Lua状态机

func (*LuaVMPool) PutLuaState added in v0.2.1

func (p *LuaVMPool) PutLuaState(L *lua.LState)

PutLuaState 将Lua状态机归还到池中

type RegisterType added in v0.2.1

type RegisterType func(L *lua.LState)

定义一个函数类型,用于作为参数传递

Jump to

Keyboard shortcuts

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