Checks and notifies of errors in lua script now

This commit is contained in:
j4nk 2023-05-26 19:53:34 -04:00
parent bb53693ace
commit 15e54bec5a
2 changed files with 13 additions and 1 deletions

4
incorrect_script.lua Normal file
View File

@ -0,0 +1,4 @@
-- Serves only to test syntax error message for oct
x = 0;
x = x + "asdf"

10
main.c
View File

@ -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);