From 62be8bc5578e1ab2fc58383c2b8923ceafd9f5e4 Mon Sep 17 00:00:00 2001 From: xfy Date: Sat, 9 May 2026 15:51:26 +0800 Subject: [PATCH] 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 --- internal/lua/engine.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/lua/engine.go b/internal/lua/engine.go index 71f75cd..b704fd1 100644 --- a/internal/lua/engine.go +++ b/internal/lua/engine.go @@ -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 }