summaryrefslogtreecommitdiff
path: root/src/read_cfg.c
diff options
context:
space:
mode:
authorLouie Shprung <lshprung@tutanota.com>2024-08-04 17:19:08 -0400
committerLouie Shprung <lshprung@tutanota.com>2024-08-04 17:19:08 -0400
commita23c315905c126667f13091989ca2879b5337582 (patch)
tree23eb508647bf90ca18282df2ab2c9cf1f3661bbd /src/read_cfg.c
parente1754801f53842c289e8c75cd29ce239693f0c19 (diff)
Hello lua
Diffstat (limited to 'src/read_cfg.c')
-rw-r--r--src/read_cfg.c21
1 files changed, 21 insertions, 0 deletions
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 <assert.h>
+#include <lua.h>
+#include <lauxlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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";