summaryrefslogtreecommitdiff
path: root/web/app.lua
diff options
context:
space:
mode:
authorrebecca <ubq323@ubq323.website>2026-09-17 20:54:44 +0100
committerrebecca <ubq323@ubq323.website>2026-09-17 20:54:44 +0100
commit6c5d5fec129a29c6250b094f46881cfa5aaadcc7 (patch)
treeb66161fccfa91180e937f0689763f2124a4af97b /web/app.lua
parent7f60b7c4e8d99f97a0a24b60bd4c4fd15697a4bb (diff)
web: import from m1msq 15b348f
Diffstat (limited to 'web/app.lua')
-rw-r--r--web/app.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/web/app.lua b/web/app.lua
new file mode 100644
index 0000000..9a7e24b
--- /dev/null
+++ b/web/app.lua
@@ -0,0 +1,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