Sat, 01 Nov 2014 23:34:21 +0000
Lua 5.2 compatibility hack
5 | 1 | |
2 | 2 | module('lgen', package.seeall) |
3 | -- export src dst hierarchy | |
4 | ||
5 | 5 | -- Lua 5.1 setfenv/getfenv compatibility for Lua 5.2 |
6 | local CE = require('compat_env') | |
7 | _G.setfenv = CE.setfenv | |
8 | _G.getfenv = CE.getfenv | |
9 | ||
2 | 10 | require('scan') |
11 | require('handlers') | |
3 | 12 | -- globally add missing stuff |
13 | require('luaext') | |
2 | 14 | |
15 | -- | |
16 | -- Main | |
17 | -- | |
18 | ||
3 | 19 | if #arg < 3 then |
20 | error("Usage: lgen src tmpl dst") | |
2 | 21 | end |
22 | ||
23 | src = arg[1] | |
3 | 24 | tmpl = arg[2] |
25 | dst = arg[3] | |
2 | 26 | |
27 | print('Scan...') | |
28 | hierarchy = scan.scan(src) | |
29 | ||
3 | 30 | |
31 | local env={ | |
32 | paths={ | |
33 | src=src, | |
34 | dst=dst, | |
35 | tmpl=tmpl, | |
36 | }, | |
37 | pages={ | |
38 | }, | |
39 | } | |
40 | ||
41 | ||
2 | 42 | -- Pitäisi env konstruoida. polun perusteella. |
43 | scan.map(hierarchy, function(f) handlers.choose(f, env) end) | |
44 | ||
45 | print('Phase 1...') | |
46 | scan.map(hierarchy, function(f) handlers.phase1(f, env) end) | |
47 | print('Phase 2...') | |
3 | 48 | scan.map(hierarchy, function(f) handlers.phase2(f, env) end, |
49 | function(d) | |
50 | --log.log("Make path "..path.join(dst, d).."\n") | |
51 | lfs.mkdir(path.join(dst, d)) | |
52 | end) | |
53 | --print('Phase 3...') | |
54 | --scan.map(hierarchy, function(f) handlers.phase3(f, env) end) |