From a23c315905c126667f13091989ca2879b5337582 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Sun, 4 Aug 2024 17:19:08 -0400 Subject: Hello lua --- src/read_cfg.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/read_cfg.c') diff --git a/src/read_cfg.c b/src/read_cfg.c index f757d6b..fa8a424 100644 --- a/src/read_cfg.c +++ b/src/read_cfg.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -43,12 +45,31 @@ bool cfg_interp(char *path){ int i=0; int j; + // check if file path exists fp = fopen(path, "r"); if(fp == NULL){ printf("Error: Invalid Configuration Path \"%s\"\n", path); return false; } + fclose(fp); + + // load lua configuration + lua_State *L = luaL_newstate(); + int config_load_status = luaL_dofile(L, path); + if(config_load_status != 0) { + printf("Error: could not load configuration \"%s\"\nis there a syntax error?\n", path); + return false; + } + + // demo + lua_getglobal(L, "Message"); + const char *message = lua_tostring(L, -1); + printf("message: %s\n", message); + + lua_close(L); + return true; + /* --- Old code --- */ //build the options array char **options = malloc(sizeof(char *) * OPTION_CNT); options[0] = "add"; -- cgit