mod_lua

mod_lua 加载 Lua 插件和动作

另请参见 Lua API

lua.plugin (设置)

将文件加载为 Lua 插件

lua.plugin (filename, options, lua-args);
文件名
包含 Lua 代码的文件
选项
一个键值表,包含选项;目前没有可用选项
lua-args
转发给 Lua 插件的参数

Lua 插件可以通过在全局 Lua 命名空间中创建 setups / actions 表来注册设置和动作回调(像任何 C 模块一样)。

文件名和第三个参数 lua-args 在 Lua 脚本中作为 ... 的参数可用。

示例

setup {
	module_load "mod_lua";
	lua.plugin "secdownload.lua";
}

插件示例

(参见 contrib/core.lua 获取真实示例)

local filename, args = ...

-- args are from the lua.plugin line

local function simple(actionarg)
	-- actionarg is the parameter from the 'single "/xxx";' action line

	-- create an action:
	return action.respond()
end

actions = {
	["simple"] = simple,
}

lua.handler (动作)

将文件加载为 Lua 配置

lua.handler (filename, options, lua-args);
文件名
包含 Lua 代码的文件
选项
一个键值表,包含以下条目
ttl
在此时间(秒)之后,将检查文件是否修改并重新加载。0 表示禁用重新加载(默认 0)
lua-args
转发给 Lua 插件的参数

lua.handler 基本与 include_lua 相同,但有以下不同之处

  • 每个工作进程自行加载 Lua 文件
  • 它在使用前才加载,因此在加载时不会看到脚本中的错误
  • 它不能调用设置函数
  • 它支持向脚本传递参数(local filename, args = ...
  • 它不锁定全局 Lua 锁,因此在使用多个工作进程时性能更好

参见 contrib/core.lua,了解我们如何加载一些外部动作,例如 contrib/core__xsendfile.lua

示例

setup {
	module_load "mod_lua";
	lua.plugin "secdownload.lua";
}

if req.path =^ "/app" {
	lua.handler "/etc/lighttpd/pathrewrite.lua", [ "ttl" => 300 ], "/app";
}