全域性 Lua 模組
全域性 Lua 模組提供了一種強大的機制,用於實現複雜邏輯功能。
與 YAML 配置檔案不同,全域性 Lua 模組以 .lua
作為副檔名,並且必須存放在配置目錄中名為 global_lua_modules
的子目錄下。
示例
建立一個名為 hello.lua
的 Lua 模組:
local _M = {}
function _M.go()
ngx.say("hello")
end
return _M
在頁面規則中呼叫 hello
Lua 模組:
- enable_rule: true
actions:
"user-code":
el: |-
{
true =>
foreign-call(module: "hello", func: "go"),
done;
}
comment: ''
在上述示例中,定義了一個簡單的 Lua 模組 hello.lua
,該模組包含了一個名為 go
的函式,用於輸出 “hello”。然後,在頁面規則的配置中,透過表示式呼叫了這個模組和函式。