Sat, 01 Nov 2014 23:34:21 +0000
Lua 5.2 compatibility hack
2 | 1 | |
2 | module("handlers", package.seeall) | |
3 | ||
4 | require("handlers.render") | |
5 | require("handlers.copy") | |
6 | require("handlers.ignore") | |
7 | ||
8 | local available={ | |
3 | 9 | { pattern = "%.lg$", handler = handlers.render}, |
4 | 10 | { pattern = "%.note$", handler = handlers.ignore}, |
3 | 11 | { pattern = "", handler = handlers.copy}, |
2 | 12 | } |
13 | ||
14 | ||
15 | function find(f) | |
16 | for _, h in ipairs(available) do | |
3 | 17 | if string.match(f, h.pattern) then |
2 | 18 | return h.handler |
19 | end | |
20 | end | |
21 | return handlers.ignore | |
22 | end | |
23 | ||
24 | local cached={} | |
25 | ||
26 | function choose(f, env) | |
27 | cached[f] = find(f) | |
28 | end | |
29 | ||
30 | -- load | |
31 | function phase1(f, env) | |
32 | return cached[f].phase1(f, env) | |
33 | end | |
34 | ||
35 | -- write | |
36 | function phase2(f, env) | |
37 | return cached[f].phase2(f, env) | |
38 | end | |
39 |