diff --git a/main.c b/main.c index aa32db4..9a4147e 100644 --- a/main.c +++ b/main.c @@ -7,13 +7,28 @@ #define TB_IMPL #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; -int initialize_everything(); +int process_args(int argc, char* argv[]); +int initialize_everything(char* lua_file); int deinitialize_everything(); + int main(int argc, char* argv[]) { - if (!initialize_everything()) { - fprintf(stderr, "Couldn't initialize Open Card Table"); + int process_args_result = process_args(argc, argv); + 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; int finish = 0; @@ -37,7 +52,15 @@ int main(int argc, char* argv[]) { 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()) { return 0; } @@ -48,11 +71,11 @@ int initialize_everything() { } luaL_openlibs(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_call(L, 0, 0); tb_init(); - return 1; + return 0; } int deinitialize_everything() { diff --git a/test b/test deleted file mode 100755 index 8839477..0000000 Binary files a/test and /dev/null differ