七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:HooksHandler

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
local module = {}

function module.init()
	local hooks = {}
	local hookTrigger = function (name, ...)
		if not hooks[name] then return ... end
		local args = {...}
		for _, func in ipairs(hooks[name]) do
			if type(func) == 'function' then
				local retn = {func(unpack(args))}
				if #retn > 0 then
					for idx, val in ipairs(retn) do
						args[idx] = val
					end
				end
			end
		end
		return unpack(args)
	end
	return function (list)
		for name, func in pairs(list) do
			if type(func) == 'function' then
				hooks[name] = hooks[name] or {}
				table.insert(hooks[name], func)
			end
		end
		return hookTrigger
	end
end

return module