summaryrefslogtreecommitdiff
path: root/src
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
parente1754801f53842c289e8c75cd29ce239693f0c19 (diff)
Hello lua
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/read_cfg.c21
-rw-r--r--src/unix/read_cfg.c6
-rw-r--r--src/windows/read_cfg.c4
4 files changed, 28 insertions, 7 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 80a550c..7fbb284 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,8 +3,8 @@ EXTRA_DIST = include unix windows
bin_PROGRAMS = terminal-media-launcher
terminal_media_launcher_SOURCES = cache.c draw.c read_cfg.c group.c entry.c $(PLATFORM)/cache.c $(PLATFORM)/draw.c $(PLATFORM)/read_cfg.c
-terminal_media_launcher_LDADD = @CURSES_LIBS@
-terminal_media_launcher_CPPFLAGS = @CURSES_CFLAGS@
+terminal_media_launcher_LDADD = @CURSES_LIBS@ @LUA_LIB@
+terminal_media_launcher_CPPFLAGS = @CURSES_CFLAGS@ @LUA_INCLUDE@
if WINDOWS
PLATFORM=windows
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";
diff --git a/src/unix/read_cfg.c b/src/unix/read_cfg.c
index b40dd48..4e58863 100644
--- a/src/unix/read_cfg.c
+++ b/src/unix/read_cfg.c
@@ -20,8 +20,8 @@ char *find_config(){
int check_count = 2;
int i;
- sprintf(choices[0], "%s%c.config%cterminal-media-launcher%cconfig", home, sep, sep, sep);
- sprintf(choices[1], "%s%c.terminal-media-launcher%cconfig", home, sep, sep);
+ sprintf(choices[0], "%s%c.config%cterminal-media-launcher%cconfig.lua", home, sep, sep, sep);
+ sprintf(choices[1], "%s%c.terminal-media-launcher%cconfig.lua", home, sep, sep);
for(i = 0; i < check_count; i++){
strcpy(path, choices[i]);
@@ -69,7 +69,7 @@ void mkconfig_wizard(char *path){
sprintf(path, "%s%c.config%cterminal-media-launcher%c", home, sep, sep, sep);
mkdir(path, 0755);
- sprintf(path, "%s%c.config%cterminal-media-launcher%cconfig", home, sep, sep, sep);
+ sprintf(path, "%s%c.config%cterminal-media-launcher%cconfig.lua", home, sep, sep, sep);
//open file for writing, make sure non-NULL
fp = fopen(path, "w");
diff --git a/src/windows/read_cfg.c b/src/windows/read_cfg.c
index f973759..9fa721b 100644
--- a/src/windows/read_cfg.c
+++ b/src/windows/read_cfg.c
@@ -20,7 +20,7 @@ char *find_config(){
char choices[check_count][BUF_LEN];
int i;
- sprintf(choices[0], "%s%cterminal-media-launcher%cconfig", appdata, sep, sep);
+ sprintf(choices[0], "%s%cterminal-media-launcher%cconfig.lua", appdata, sep, sep);
for(i = 0; i < check_count; i++){
strcpy(path, choices[i]);
@@ -72,7 +72,7 @@ void mkconfig_wizard(char *path){
sprintf(path, "%s%cterminal-media-launcher%c", appdata, sep, sep);
mkdir(path);
- sprintf(path, "%s%cterminal-media-launcher%cconfig", appdata, sep, sep);
+ sprintf(path, "%s%cterminal-media-launcher%cconfig.lua", appdata, sep, sep);
//open file for writing, make sure non-NULL
fp = fopen(path, "w");