Engine 0.0.4
Game engine in lua
Loading...
Searching...
No Matches
main.lua
Go to the documentation of this file.
1local os = require('os')
2local zeebo_bundler = require('src/lib/cli/bundler')
3local zeebo_args = require('src/lib/common/args')
4local zeebo_meta = require('src/lib/cli/meta')
5local zeebo_fs = require('src/lib/cli/fs')
6
7--! @cond
8local run = zeebo_args.has(arg, 'run')
9local bundler = zeebo_args.has(arg, 'bundler')
10local coverage = zeebo_args.has(arg, 'coverage')
11local core = zeebo_args.get(arg, 'core', 'ginga')
12local dist = zeebo_args.get(arg, 'dist', './dist/')
13local screen = zeebo_args.get(arg, 'screen', '1280x720')
14local command = zeebo_args.param(arg, {'core', 'screen', 'dist'}, 1, 'help')
15local game = zeebo_args.param(arg, {'core', 'screen', 'dist'}, 2, '')
16
17local core_list = {
18 repl={
19 src='src/engine/core/repl/main.lua',
20 exe='lua src/engine/core/repl/main.lua '..game,
21 post_exe='lua dist/main.lua'
22 },
23 love={
24 src='src/engine/core/love/main.lua',
25 exe='love src/engine/core/love --screen '..screen..' '..game,
26 post_exe='love dist --screen '..screen
27 },
28 ginga={
29 src='src/engine/core/ginga/main.lua',
30 post_exe='ginga dist/main.ncl -s '..screen,
31 extras={
32 'src/engine/core/ginga/main.ncl'
33 }
34 },
35 native={
36 src='src/engine/core/native/main.lua',
37 },
38 html5_webos={
39 src='src/engine/core/native/main.lua',
40 post_exe='webos24 $(pwd)/dist',
41 pipeline={
42 zeebo_meta.late(game):file(dist..'index.html'):file(dist..'appinfo.json'):pipe()
43 },
44 extras={
45 'src/engine/meta/html5_webos/appinfo.json',
46 'src/engine/core/html5/index.html',
47 'src/engine/core/html5/index.html',
48 'src/engine/core/html5/engine.js',
49 'assets/icon80x80.png'
50 }
51 },
52 html5_tizen={
53 src='src/engine/core/native/main.lua',
54 pipeline={
55 zeebo_meta.late(game):file(dist..'index.html'):file(dist..'config.xml'):pipe(),
56 function() os.execute('cd '..dist..';~/tizen-studio/tools/ide/bin/tizen.sh package -t wgt;true') end
57 },
58 extras={
59 'src/engine/meta/html5_tizen/config.xml',
60 'src/engine/meta/html5_tizen/.tproject',
61 'src/engine/core/html5/index.html',
62 'src/engine/core/html5/index.html',
63 'src/engine/core/html5/engine.js',
64 'assets/icon80x80.png'
65 }
66 },
67 html5_ginga={
68 src='src/engine/core/native/main.lua',
69 post_exe='ginga dist/main.ncl -s '..screen,
70 pipeline={
71 zeebo_meta.late(game):file(dist..'index.html'):pipe()
72 },
73 extras={
74 'src/engine/meta/html5_ginga/main.ncl',
75 'src/engine/core/html5/index.html',
76 'src/engine/core/html5/index.html',
77 'src/engine/core/html5/engine.js',
78 }
79 },
80 html5={
81 src='src/engine/core/native/main.lua',
82 pipeline={
83 zeebo_meta.late(game):file(dist..'index.html'):pipe()
84 },
85 extras={
86 'src/engine/core/html5/index.html',
87 'src/engine/core/html5/engine.js'
88 }
89 },
90 nintendo_wii={
91 src='src/engine/core/nintendo_wii/main.lua',
92 pipeline={
93 zeebo_meta.late(game):file(dist..'meta.xml'):pipe()
94 },
95 extras={
96 'assets/icon128x48.png',
97 'src/engine/meta/nintendo_wii/meta.xml'
98 }
99 }
100}
101
102if command == 'run' then
103 if not zeebo_args.get(arg, 'core') then
104 core = 'love'
105 end
106 if not core_list[core] or not core_list[core].exe then
107 print('this core cannot be runned!')
108 os.exit(1)
109 end
110 os.exit(os.execute(core_list[core].exe) and 0 or 1)
111elseif command == 'clear' or command == 'clean' then
112 zeebo_fs.clear(dist)
113elseif command == 'meta' then
114 if core == 'ginga' then
115 core = '{{title}} {{version}}'
116 end
117 zeebo_meta.current(game):stdout(core):run()
118elseif command == 'bundler' then
119 local path, file = game:match("(.-)([^/\\]+)$")
120 zeebo_bundler.build(path, file, dist..file)
121elseif command == 'test-self' then
122 coverage = coverage and '-lluacov' or ''
123 local files = zeebo_fs.ls('./tests')
124 local index = 1
125 local ok = true
126 while index <= #files do
127 ok = ok and os.execute('lua '..coverage..' ./tests/'..files[index])
128 index = index + 1
129 end
130 if #coverage > 0 then
131 os.execute('luacov src')
132 os.execute('tail -n '..tostring(#files + 5)..' luacov.report.out')
133 end
134 if not ok then
135 os.exit(1)
136 end
137elseif command == 'build' then
138 -- clean dist
139 zeebo_fs.clear(dist)
140
141 -- check core
142 if not core_list[core] then
143 print('this core cannot be build!')
144 os.exit(1)
145 end
146
147 -- force html5 to bundler
148 if core:find('html5') then
149 bundler = true
150 end
151
152 -- pre bundler
153 if bundler then
154 bundler = '_bundler/'
155 zeebo_fs.clear(dist..bundler)
156 else
157 bundler = ''
158 end
159
160 -- move game
161 if game and #game > 0 then
162 zeebo_fs.move(game, dist..'game.lua')
163 end
164
165 -- core move
166 local index = 1
167 local core = core_list[core]
168 zeebo_fs.build(core.src, dist..bundler)
169 if core.extras then
170 while index <= #core.extras do
171 local file = core.extras[index]
172 zeebo_fs.move(file, dist..file:gsub('.*/', ''))
173 index = index + 1
174 end
175 end
176
177 -- combine files
178 if #bundler > 0 then
179 zeebo_bundler.build(dist..bundler, 'main.lua', dist..'main.lua')
180 zeebo_fs.clear(dist..bundler)
181 end
182
183 -- post process
184 if core.pipeline then
185 local index = 1
186 while index <= #core.pipeline do
187 local eval = core.pipeline[index]
188 while type(eval) == 'function' do
189 eval = eval()
190 end
191 index = index + 1
192 end
193 end
194
195 if run then
196 if not core.post_exe then
197 print('this core cannot be runned after build!')
198 os.exit(1)
199 end
200 os.exit(os.execute(core.post_exe) and 0 or 1)
201 end
202elseif command == "help" then
203 local help_message = "Available commands:\n" ..
204 "- run: Executes the specified core. If no core is specified, defaults to 'love'.\n" ..
205 "- clear | clean: Clears the specified distribution directory.\n" ..
206 "- meta: Displays metadata for the current game.\n" ..
207 "- bundler: Builds the game using the bundler.\n" ..
208 "- test-self: Runs tests located in the './tests' directory.\n" ..
209 "- build: Builds the game and prepares it for distribution.\n" ..
210 "\n" ..
211 "Available cores:\n" ..
212 "- repl: Runs the REPL core.\n" ..
213 "- love: Runs the Love2D core.\n" ..
214 "- ginga: Runs the Ginga core.\n" ..
215 "- html5_webos: Builds for HTML5 on WebOS.\n" ..
216 "- html5_tizen: Builds for HTML5 on Tizen.\n" ..
217 "- html5_ginga: Runs the Ginga core for HTML5.\n" ..
218 "- html5: Runs the standard HTML5 core.\n" ..
219 "- nintendo_wii: Builds for the Nintendo Wii.\n" ..
220 "\n" ..
221 "Usage:\n" ..
222 "- To run a command, use: ./cli.sh <command> <game_path> --core <core_name> [options]\n" ..
223 "- For example: ./cli.sh build ./examples/asteroids/game.lua --core ginga"
224 print(help_message)
225else
226 print('command not found: '..command)
227 os.exit(1)
228end
229
230--! @endcond
local function stdout(self, format)
local function pipe(self)
local function run(self)
local function file(self, file)
local function move(src_in, dist_out)
local function require(std, game, application)
local function param(self, name, value)
local zeebo_args
Definition main.lua:3
local zeebo_meta
Definition main.lua:4
local zeebo_bundler
Definition main.lua:2
local zeebo_fs
Definition main.lua:5
local os
Definition main.lua:1
local game
Definition main.lua:17