lolly/internal/lua/api_ctx.go
xfy 8b382606df Merge branch 'lint-fix' - resolve sendfile.go conflict
Conflict: sendfile.go (!linux build tag) was incorrectly modified to
include linuxSendfile and getSocketFd functions which already exist
in sendfile_linux.go.

Resolution: Keep HEAD version (simple fallback returning ENOTSUP) as
Linux implementation is properly separated in sendfile_linux.go.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:26:48 +08:00

32 lines
984 B
Go
Raw 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 实现
package lua
import (
glua "github.com/yuin/gopher-lua"
)
// RegisterNgxCtxAPI 在 Lua 状态机中注册 ngx.ctx API
// ngx.ctx 是一个普通的 Lua table每请求独立支持任意 Lua 值类型
func RegisterNgxCtxAPI(L *glua.LState, ngxTable *glua.LTable) {
// 创建请求级的 ctx table
ctxTable := L.NewTable()
// 将 ngx.ctx 添加到 ngx 表
ngxTable.RawSetString("ctx", ctxTable)
}
// RegisterSchedulerUnsafeCtxAPI 为 Scheduler LState 注册不安全的 ngx.ctx API
func RegisterSchedulerUnsafeCtxAPI(L *glua.LState, ngx *glua.LTable) {
ctxTable := L.NewTable()
mt := L.NewTable()
mt.RawSetString("__index", L.NewFunction(luaSchedulerUnsafeCtx))
mt.RawSetString("__newindex", L.NewFunction(luaSchedulerUnsafeCtx))
L.SetMetatable(ctxTable, mt)
ngx.RawSetString("ctx", ctxTable)
}
func luaSchedulerUnsafeCtx(L *glua.LState) int {
L.RaiseError("API ngx.ctx not available in timer callback context")
return 0
}