feat(lua): enable package library and preload gjson module

Add glua.OpenPackage for require support and preload gjson module
to make JSON encoding/decoding available in Lua scripts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-09 15:51:26 +08:00
parent 376b9fd33c
commit 62be8bc557

View File

@ -33,6 +33,8 @@ import (
"github.com/valyala/fasthttp"
glua "github.com/yuin/gopher-lua"
"rua.plus/lolly/gjson"
)
// LuaEngine 全局 Lua 引擎。
@ -176,6 +178,7 @@ func NewEngine(config *Config) (*LuaEngine, error) {
glua.OpenString(L)
glua.OpenMath(L)
glua.OpenCoroutine(L)
glua.OpenPackage(L) // 需要 package 库支持 require
// 可选加载危险库
if config.EnableOSLib {
@ -185,6 +188,9 @@ func NewEngine(config *Config) (*LuaEngine, error) {
glua.OpenIo(L)
}
// 预加载 gjson 模块
gjson.Preload(L)
return L
}