mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-31 09:19:15 +02:00
make lua work on return
This commit is contained in:
+11
-15
@@ -1,15 +1,11 @@
|
|||||||
cmd_output = ""
|
-- if type(cmd) == "string" then
|
||||||
|
-- if cmd:sub(1, 3) == "PI=" then
|
||||||
if type(cmd) == "string" then
|
-- local hex = cmd:sub(7)
|
||||||
if cmd:sub(1, 3) == "PI=" then
|
-- local pi = tonumber(hex, 16)
|
||||||
local hex = cmd:sub(7)
|
-- if (pi & 0xf000) == 0 then return "-" end
|
||||||
local pi = tonumber(hex, 16)
|
-- if pi then
|
||||||
|
-- set_rds_pi(pi)
|
||||||
if pi then
|
-- return "+"
|
||||||
set_rds_pi(pi)
|
-- end
|
||||||
cmd_output = string.format("+", pi)
|
-- end
|
||||||
else
|
-- end
|
||||||
cmd_output = "Invalid hex PI"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
+7
-10
@@ -24,20 +24,17 @@ void run_lua(char *str, char *cmd_output) {
|
|||||||
|
|
||||||
char path[128];
|
char path[128];
|
||||||
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
|
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);
|
const char *err = lua_tostring(L, -1);
|
||||||
fprintf(stderr, "Lua error: %s\n", err);
|
fprintf(stderr, "Lua error: %s\n", err);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
lua_settop(L, top);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user