Added in errors, ability to specify lua file
This commit is contained in:
parent
c65a87fab6
commit
1607652f62
35
main.c
35
main.c
|
@ -7,13 +7,28 @@
|
||||||
#define TB_IMPL
|
#define TB_IMPL
|
||||||
#include "termbox.h"
|
#include "termbox.h"
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
#define OCT_NO_LUA_FILE 1
|
||||||
|
#define OCT_LUA_FILE_NOT_FOUND 2
|
||||||
|
#define OCT_LUA_FILE_MISSING_OCT_INIT 3
|
||||||
|
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
|
|
||||||
int initialize_everything();
|
int process_args(int argc, char* argv[]);
|
||||||
|
int initialize_everything(char* lua_file);
|
||||||
int deinitialize_everything();
|
int deinitialize_everything();
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (!initialize_everything()) {
|
int process_args_result = process_args(argc, argv);
|
||||||
fprintf(stderr, "Couldn't initialize Open Card Table");
|
switch (process_args_result) {
|
||||||
|
case OCT_NO_LUA_FILE:
|
||||||
|
fprintf(stderr, "No lua file given\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
break;
|
||||||
|
case OCT_LUA_FILE_NOT_FOUND:
|
||||||
|
fprintf(stderr, "Could not open file: %s\n", argv[argc-1]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
struct tb_event ev;
|
struct tb_event ev;
|
||||||
int finish = 0;
|
int finish = 0;
|
||||||
|
@ -37,7 +52,15 @@ int main(int argc, char* argv[]) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initialize_everything() {
|
int process_args(int argc, char* argv[]) {
|
||||||
|
if (argc == 1) { // Didn't specify a file
|
||||||
|
return OCT_NO_LUA_FILE;
|
||||||
|
}
|
||||||
|
// TODO define other cmd line args here
|
||||||
|
return initialize_everything(argv[argc-1]); // lua file should always be last argument
|
||||||
|
}
|
||||||
|
|
||||||
|
int initialize_everything(char* lua_file) {
|
||||||
if (!oct_tb_sprite_list_initialize()) {
|
if (!oct_tb_sprite_list_initialize()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -48,11 +71,11 @@ int initialize_everything() {
|
||||||
}
|
}
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
oct_tb_initialize_lua(L);
|
oct_tb_initialize_lua(L);
|
||||||
luaL_dofile(L, "pong.lua");
|
if (luaL_dofile(L, lua_file)) return OCT_LUA_FILE_NOT_FOUND;
|
||||||
lua_getglobal(L, "oct_init");
|
lua_getglobal(L, "oct_init");
|
||||||
lua_call(L, 0, 0);
|
lua_call(L, 0, 0);
|
||||||
tb_init();
|
tb_init();
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int deinitialize_everything() {
|
int deinitialize_everything() {
|
||||||
|
|
Loading…
Reference in New Issue