Skip to content

Commit 847e0b5

Browse files
author
Peter Kosyh
committed
-x option
1 parent a4604bb commit 847e0b5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

main.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
#include <windows.h>
3333
#endif
3434
#include "instead/src/instead/instead.h"
35-
35+
#include "instead/src/instead/util.h"
3636
#define WIDTH 70
3737

3838
static int opt_log = 0;
39+
static int opt_lua = 0;
3940
static int opt_debug = 0;
4041
static int opt_width = WIDTH;
4142
static char *opt_autoload = NULL;
@@ -220,6 +221,7 @@ int main(int argc, const char **argv)
220221

221222
int parser_mode = 0;
222223
int menu_mode = 0;
224+
int opt_args = 0;
223225

224226
setlocale(LC_ALL, "");
225227
for (i = 1; i < argc; i++) {
@@ -233,6 +235,8 @@ int main(int argc, const char **argv)
233235
} else if (!strcmp(argv[i], "-a")) {
234236
opt_autoload = strdup("autosave");
235237
opt_autosave = 1;
238+
} else if (!strcmp(argv[i], "-x")) {
239+
opt_lua = 1;
236240
} else if (!strncmp(argv[i], "-d", 2)) {
237241
opt_debug = 1;
238242
reopen_stderr(argv[i] + 2);
@@ -242,6 +246,7 @@ int main(int argc, const char **argv)
242246
reopen_stdin(argv[i] + 2);
243247
} else if (!game) {
244248
game = argv[i];
249+
opt_args = i + 1;
245250
}
246251
}
247252
#ifdef _WIN32
@@ -263,6 +268,18 @@ int main(int argc, const char **argv)
263268
fclose(stderr);
264269

265270
instead_set_debug(opt_debug);
271+
272+
if (opt_lua) {
273+
rc = instead_init_lua(dirpath(game), 0);
274+
show_err();
275+
if (rc)
276+
exit(1);
277+
rc = instead_loadscript((char*)game, argc - opt_args, (char **)argv + opt_args, 1);
278+
show_err();
279+
instead_done();
280+
exit(!!rc);
281+
}
282+
266283
restart:
267284
if (instead_init(game)) {
268285
fprintf(stdout, "Can not init game: %s (%s)\n", game, instead_err());

0 commit comments

Comments
 (0)