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:
parent
376b9fd33c
commit
62be8bc557
@ -33,6 +33,8 @@ import (
|
|||||||
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
glua "github.com/yuin/gopher-lua"
|
glua "github.com/yuin/gopher-lua"
|
||||||
|
|
||||||
|
"rua.plus/lolly/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LuaEngine 全局 Lua 引擎。
|
// LuaEngine 全局 Lua 引擎。
|
||||||
@ -176,6 +178,7 @@ func NewEngine(config *Config) (*LuaEngine, error) {
|
|||||||
glua.OpenString(L)
|
glua.OpenString(L)
|
||||||
glua.OpenMath(L)
|
glua.OpenMath(L)
|
||||||
glua.OpenCoroutine(L)
|
glua.OpenCoroutine(L)
|
||||||
|
glua.OpenPackage(L) // 需要 package 库支持 require
|
||||||
|
|
||||||
// 可选加载危险库
|
// 可选加载危险库
|
||||||
if config.EnableOSLib {
|
if config.EnableOSLib {
|
||||||
@ -185,6 +188,9 @@ func NewEngine(config *Config) (*LuaEngine, error) {
|
|||||||
glua.OpenIo(L)
|
glua.OpenIo(L)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 预加载 gjson 模块
|
||||||
|
gjson.Preload(L)
|
||||||
|
|
||||||
return L
|
return L
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user