handlers.lua

Sat, 01 Nov 2014 23:34:21 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 01 Nov 2014 23:34:21 +0000
changeset 5
7667b101cb1e
parent 4
4cb0d1dbc65b
child 7
038275cd92ed
permissions
-rwxr-xr-x

Lua 5.2 compatibility hack

2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 module("handlers", package.seeall)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 require("handlers.render")
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 require("handlers.copy")
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 require("handlers.ignore")
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 local available={
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
9 { pattern = "%.lg$", handler = handlers.render},
4
Tuomo Valkonen <tuomov@iki.fi>
parents: 3
diff changeset
10 { pattern = "%.note$", handler = handlers.ignore},
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
11 { pattern = "", handler = handlers.copy},
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 }
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 function find(f)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 for _, h in ipairs(available) do
3
b2df1b3f2c83 Improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 2
diff changeset
17 if string.match(f, h.pattern) then
2
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 return h.handler
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 return handlers.ignore
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24 local cached={}
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 function choose(f, env)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 cached[f] = find(f)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 -- load
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 function phase1(f, env)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 return cached[f].phase1(f, env)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 -- write
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 function phase2(f, env)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 return cached[f].phase2(f, env)
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 end
3975fa5ed630 (don't know)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39

mercurial