summaryrefslogtreecommitdiff
path: root/web/app.lua
blob: 9a7e24ba83ac1e6acae8dc4dd92958522228d08f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local class = require'r.class'

local App = class()
function App.make(cls, fields)
	fields.hooks = fields.hooks or {
		pre_start = {},
		pre_req = {},
		post_req = {}}
	return setmetatable(fields,cls) end
function App.add_hook(self,name,fn)
	local lst = self.hooks[name]
	assert(lst, 'unknown hook name')
	local ix = name:match"^post" and 1 or #lst+1
	table.insert(lst, ix, fn) end
function App.run_hooks(self,name,...)
	local lst = self.hooks[name]
	assert(lst,'unknown hook name')
	for i,f in ipairs(lst) do f(...) end end
return App