Tue, 16 Jan 2018 16:39:48 +0000
Convert module stuff to lua 5.3
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
1 | |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
2 | local path=string.gsub(arg[0], "(.*)/[^/]*", "%1"); |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
3 | if path~=nil then |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
4 | package.path=package.path .. ';' .. path .. '/?.lua' |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
5 | end |
2 | 6 | |
5 | 7 | -- Lua 5.1 setfenv/getfenv compatibility for Lua 5.2 |
8 | local CE = require('compat_env') | |
9 | _G.setfenv = CE.setfenv | |
10 | _G.getfenv = CE.getfenv | |
11 | ||
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
12 | local scan=require('scan') |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
13 | local handlers=require('handlers') |
3 | 14 | -- globally add missing stuff |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
15 | local luaext=require('luaext') |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
16 | local lfs=require('lfs') |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
17 | local path=require('path') |
2 | 18 | |
19 | -- | |
20 | -- Main | |
21 | -- | |
22 | ||
3 | 23 | if #arg < 3 then |
24 | error("Usage: lgen src tmpl dst") | |
2 | 25 | end |
26 | ||
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
27 | local src = arg[1] |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
28 | local tmpl = arg[2] |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
29 | local dst = arg[3] |
2 | 30 | |
31 | print('Scan...') | |
7
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
32 | |
038275cd92ed
Convert module stuff to lua 5.3
Tuomo Valkonen <tuomov@iki.fi>
parents:
5
diff
changeset
|
33 | local hierarchy = scan.scan(src) |
2 | 34 | |
3 | 35 | |
36 | local env={ | |
37 | paths={ | |
38 | src=src, | |
39 | dst=dst, | |
40 | tmpl=tmpl, | |
41 | }, | |
42 | pages={ | |
43 | }, | |
44 | } | |
45 | ||
46 | ||
2 | 47 | -- Pitäisi env konstruoida. polun perusteella. |
48 | scan.map(hierarchy, function(f) handlers.choose(f, env) end) | |
49 | ||
50 | print('Phase 1...') | |
51 | scan.map(hierarchy, function(f) handlers.phase1(f, env) end) | |
52 | print('Phase 2...') | |
3 | 53 | scan.map(hierarchy, function(f) handlers.phase2(f, env) end, |
54 | function(d) | |
55 | --log.log("Make path "..path.join(dst, d).."\n") | |
56 | lfs.mkdir(path.join(dst, d)) | |
57 | end) | |
58 | --print('Phase 3...') | |
59 | --scan.map(hierarchy, function(f) handlers.phase3(f, env) end) |