From 1a747d92646b22924904a7f05a218023ffbaf41c Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 22 Dec 2025 15:03:12 +0100 Subject: [PATCH] make lua work on return --- src/command.lua | 26 +++++++++++--------------- src/lua_rds.c | 17 +++++++---------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/command.lua b/src/command.lua index 5fb11d8..4c199b6 100644 --- a/src/command.lua +++ b/src/command.lua @@ -1,15 +1,11 @@ -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 +-- if type(cmd) == "string" then +-- if cmd:sub(1, 3) == "PI=" then +-- local hex = cmd:sub(7) +-- local pi = tonumber(hex, 16) +-- if (pi & 0xf000) == 0 then return "-" end +-- if pi then +-- set_rds_pi(pi) +-- return "+" +-- end +-- end +-- end \ No newline at end of file diff --git a/src/lua_rds.c b/src/lua_rds.c index d05a5e0..279c5db 100644 --- a/src/lua_rds.c +++ b/src/lua_rds.c @@ -24,20 +24,17 @@ void run_lua(char *str, char *cmd_output) { char path[128]; snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME")); - if (luaL_dofile(L, path) != LUA_OK) { + if (luaL_loadfilex(L, path, NULL) == LUA_OK && lua_pcall(L, 0, 1, 0) == LUA_OK) { + if (lua_isstring(L, -1)) { + const char * message = lua_tostring(L, -1); + if(cmd_output) strcpy(cmd_output, message); + } + lua_pop(L, 1); + } else { const char *err = lua_tostring(L, -1); fprintf(stderr, "Lua error: %s\n", err); lua_pop(L, 1); lua_settop(L, top); - return; - } - - lua_getglobal(L, "cmd_output"); - - if (lua_isstring(L, -1)) { - const char * message = lua_tostring(L, -1); - lua_pop(L, 1); - if(cmd_output) strcpy(cmd_output, message); } }