From a23c315905c126667f13091989ca2879b5337582 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Sun, 4 Aug 2024 17:19:08 -0400 Subject: Hello lua --- compile_commands.json | 56 ++++++++++++++++++++++++++++---------------------- configure.ac | 3 +++ src/Makefile.am | 4 ++-- src/read_cfg.c | 21 +++++++++++++++++++ src/unix/read_cfg.c | 6 +++--- src/windows/read_cfg.c | 4 ++-- 6 files changed, 63 insertions(+), 31 deletions(-) diff --git a/compile_commands.json b/compile_commands.json index cfbbf2d..cdb203b 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -7,6 +7,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -14,9 +15,9 @@ "terminal_media_launcher-cache.o", "cache.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/cache.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/terminal_media_launcher-cache.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/cache.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/terminal_media_launcher-cache.o" }, { "arguments": [ @@ -26,6 +27,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -33,9 +35,9 @@ "terminal_media_launcher-draw.o", "draw.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/draw.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/terminal_media_launcher-draw.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/draw.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/terminal_media_launcher-draw.o" }, { "arguments": [ @@ -45,6 +47,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -52,9 +55,9 @@ "terminal_media_launcher-read_cfg.o", "read_cfg.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/read_cfg.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/terminal_media_launcher-read_cfg.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/read_cfg.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/terminal_media_launcher-read_cfg.o" }, { "arguments": [ @@ -64,6 +67,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -71,9 +75,9 @@ "terminal_media_launcher-group.o", "group.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/group.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/terminal_media_launcher-group.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/group.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/terminal_media_launcher-group.o" }, { "arguments": [ @@ -83,6 +87,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -90,9 +95,9 @@ "terminal_media_launcher-entry.o", "entry.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/entry.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/terminal_media_launcher-entry.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/entry.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/terminal_media_launcher-entry.o" }, { "arguments": [ @@ -102,6 +107,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -109,9 +115,9 @@ "unix/terminal_media_launcher-cache.o", "unix/cache.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/cache.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/terminal_media_launcher-cache.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/unix/cache.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/unix/terminal_media_launcher-cache.o" }, { "arguments": [ @@ -121,6 +127,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -128,9 +135,9 @@ "unix/terminal_media_launcher-draw.o", "unix/draw.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/draw.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/terminal_media_launcher-draw.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/unix/draw.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/unix/terminal_media_launcher-draw.o" }, { "arguments": [ @@ -140,6 +147,7 @@ "-I..", "-D_DEFAULT_SOURCE", "-D_XOPEN_SOURCE=600", + "-I/usr/include/lua5.1", "-g", "-O2", "-c", @@ -147,8 +155,8 @@ "unix/terminal_media_launcher-read_cfg.o", "unix/read_cfg.c" ], - "directory": "/home/louie/Documents/code/terminal-media-launcher/source/src", - "file": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/read_cfg.c", - "output": "/home/louie/Documents/code/terminal-media-launcher/source/src/unix/terminal_media_launcher-read_cfg.o" + "directory": "/home/louie/Documents/code/terminal-media-launcher/src", + "file": "/home/louie/Documents/code/terminal-media-launcher/src/unix/read_cfg.c", + "output": "/home/louie/Documents/code/terminal-media-launcher/src/unix/terminal_media_launcher-read_cfg.o" } ] diff --git a/configure.ac b/configure.ac index 81b0c42..f922ecf 100644 --- a/configure.ac +++ b/configure.ac @@ -7,12 +7,15 @@ AM_INIT_AUTOMAKE([foreign]) # Checks for programs. AC_PROG_CC +AX_PROG_LUA(,,,[AC_MSG_ERROR([requires lua])]) # Checks for libraries. AC_CHECK_LIB([ncurses], [initscr]) +AX_LUA_LIBS # Checks for header files. AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) +AX_LUA_HEADERS # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL 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 +#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"; 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"); -- cgit