diff --git a/incorrect_script.lua b/incorrect_script.lua new file mode 100644 index 0000000..5edce5f --- /dev/null +++ b/incorrect_script.lua @@ -0,0 +1,4 @@ +-- Serves only to test syntax error message for oct + +x = 0; +x = x + "asdf" diff --git a/main.c b/main.c index 29aeef5..add143e 100644 --- a/main.c +++ b/main.c @@ -19,6 +19,7 @@ #define OCT_VERS 5 #define OCT_INVALID_ARGUMENT 6 #define OCT_NETWORK_ERROR 7 +#define OCT_LUA_FILE_SYNTAX_ERROR 8 #define OCT_MAX_FILENAME_SIZE 1024 @@ -80,6 +81,10 @@ int main(int argc, char* argv[]) { fprintf(stderr, "Error: network\n"); deinitialize_everything(); return EXIT_FAILURE; + case OCT_LUA_FILE_SYNTAX_ERROR: + fprintf(stderr, "Error: given lua file had syntax error\n"); + deinitialize_everything(); + return EXIT_FAILURE; } // initialize SIGINT handler @@ -216,7 +221,10 @@ int initialize_everything(char* lua_file) { luaL_openlibs(L); oct_tb_initialize_lua(L); oct_log_init_lua(L); - if (luaL_dofile(L, lua_file)) return OCT_LUA_FILE_NOT_FOUND; + if (luaL_dofile(L, lua_file)) { + OCT_LOG_ERROR("%s", luaL_checkstring(L, -1)); + return OCT_LUA_FILE_SYNTAX_ERROR; + } OCT_LOG_INFO("Begin running oct_init()"); lua_getglobal(L, "oct_init"); lua_call(L, 0, 2);