Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
builder.lua
Go to the documentation of this file.
1local function move(src_in, dist_path, dist_file)
2 local deps = {}
3 local pattern = "local ([%w_%-]+) = require%('src/(.-)'%)"
4 local src_file = io.open(src_in, "r")
5 local dist_file_normalized = src_in:gsub('/', '_'):gsub('^src_', '')
6 local dist_out = dist_path:gsub('/$', '')..'/'..(dist_file or dist_file_normalized)
7 local dist_file = io.open(dist_out, "w")
8
9 if src_file and dist_file then
10 repeat
11 local line = src_file:read()
12 if line then
13 local line_require = { line:match(pattern) }
14 if line_require and #line_require > 0 then
15 local var_name = line_require[1]
16 local module_path = line_require[2]
17 deps[#deps + 1] = 'src/'..module_path..'.lua'
18 dist_file:write('local '..var_name..' = require(\''..module_path:gsub('/', '_')..'\')\n')
19 else
20 dist_file:write(line, '\n')
21 end
22 end
23 until not line
24 end
25
26 if src_file then
27 src_file:close()
28 end
29 if dist_file then
30 dist_file:close()
31 end
32
33 return deps
34end
35
36local function build(src_in, dist_path)
37 local main = true
38 local deps = {}
39 local deps_builded = {}
40
41 repeat
42 if src_in:sub(-4) == '.lua' then
43 local index = 1
44 local index_deps = #deps
45 local file_name = main and 'main.lua'
46 local new_deps = move(src_in, dist_path, file_name)
47 while index <= #new_deps do
48 deps[index_deps + index] = new_deps[index]
49 index = index + 1
50 end
51 end
52
53 main = false
54 src_in = nil
55 local index = 1
56 while index <= #deps and not src_in do
57 local dep = deps[index]
58 if not deps_builded[dep] then
59 deps_builded[dep] = true
60 src_in = dep
61 end
62 index = index + 1
63 end
64 until not src_in
65end
66
67local P = {
68 move=move,
69 build=build
70}
71
72return P
build
Definition build.lua:20
local function move(src_in, dist_path, dist_file)
local function main()
local function line(x1, y1, x2, y2)