lolly/internal/lua/api_ctx.go
xfy 2734b04d8f refactor: remove 16.8k lines of dead code across all internal packages
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00

37 lines
1.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package lua 提供 ngx.ctx API 实现。
//
// 该文件实现 ngx.ctx 子模块,提供每请求独立的 Lua table 存储。
// ngx.ctx 是 OpenResty/ngx_lua 中的标准 API允许在请求生命周期内
// 跨不同阶段rewrite、access、content、log共享数据。
//
// 注意事项:
// - ngx.ctx 在 timer callback 上下文中不可用
//
// 作者xfy
package lua
import (
glua "github.com/yuin/gopher-lua"
)
// RegisterNgxCtxAPI 在 Lua 状态机中注册 ngx.ctx API。
//
// ngx.ctx 是一个每请求独立的 Lua table可通过 ngx.ctx.key 或 ngx.ctx[key]
// 读写任意 Lua 值类型字符串、数字、table 等)。
//
// 参数:
// - L: Lua 状态
// - ngxTable: ngx 全局表
func RegisterNgxCtxAPI(L *glua.LState, ngxTable *glua.LTable) {
// 检查 ngx.ctx 是否已存在,避免并发写入
if existing := ngxTable.RawGetString("ctx"); existing != glua.LNil {
return
}
// 创建请求级的 ctx table
ctxTable := L.NewTable()
// 将 ngx.ctx 添加到 ngx 表
ngxTable.RawSetString("ctx", ctxTable)
}