From f2dcf8563c4b24803644ca3a3a3aa1d8371c187d Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 22 Dec 2025 14:51:57 +0100 Subject: [PATCH] command parsing is moving to lua --- CMakeLists.txt | 7 +++++++ src/command.lua | 15 +++++++++++++++ src/lua_rds.c | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/command.lua diff --git a/CMakeLists.txt b/CMakeLists.txt index b2acce2..4e5d40b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,3 +17,10 @@ target_include_directories(rds95 PRIVATE ${LUA_INCLUDE_DIR}) target_link_libraries(rds95 PRIVATE m pthread pulse pulse-simple inih ${LUA_LIBRARIES}) install(TARGETS rds95 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + +install(CODE +" + execute_process(COMMAND ${CMAKE_COMMAND} -E copy + \"${CMAKE_CURRENT_SOURCE_DIR}/src/command.lua\" + \"$ENV{HOME}/.rds95.command.lua\") +") diff --git a/src/command.lua b/src/command.lua new file mode 100644 index 0000000..5fb11d8 --- /dev/null +++ b/src/command.lua @@ -0,0 +1,15 @@ +cmd_output = "" + +if type(cmd) == "string" then + if cmd:sub(1, 3) == "PI=" then + local hex = cmd:sub(7) + local pi = tonumber(hex, 16) + + if pi then + set_rds_pi(pi) + cmd_output = string.format("+", pi) + else + cmd_output = "Invalid hex PI" + end + end +end \ No newline at end of file diff --git a/src/lua_rds.c b/src/lua_rds.c index 01df95e..d05a5e0 100644 --- a/src/lua_rds.c +++ b/src/lua_rds.c @@ -23,7 +23,7 @@ void run_lua(char *str, char *cmd_output) { int top = lua_gettop(L); char path[128]; - snprintf(path, sizeof(path), "%s/.command95.lua", getenv("HOME")); + snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME")); if (luaL_dofile(L, path) != LUA_OK) { const char *err = lua_tostring(L, -1); fprintf(stderr, "Lua error: %s\n", err);