0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-27 04:43:52 +01:00

something

This commit is contained in:
2025-12-24 13:19:43 +01:00
parent 73beb35913
commit f3121f1580
6 changed files with 107 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
if type(data) == "string" and data ~= nil then
function data_handle(data)
local cmd, value = data:match("([^=]+)=([^=]+)")
if cmd == nil then
data = data:lower()
@@ -64,6 +64,7 @@ if type(data) == "string" and data ~= nil then
end
end
---@diagnostic disable-next-line: need-check-nil
cmd = cmd:lower()
local eon_num, eon_type = cmd:match("^eon(%d+)([a-z]+)$")

View File

@@ -515,23 +515,78 @@ void init_lua(RDSModulator* rds_mod) {
}
void run_lua(char *str, char *cmd_output) {
lua_pushstring(L, str);
lua_setglobal(L, "data");
int top = lua_gettop(L);
char path[128];
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
if (luaL_loadfilex(L, path, NULL) == LUA_OK && lua_pcall(L, 0, 1, 0) == LUA_OK) {
if (lua_isstring(L, -1)) {
if(cmd_output) strcpy(cmd_output, lua_tostring(L, -1));
const char *home = getenv("HOME");
if (!home) return;
snprintf(path, sizeof(path), "%s/.rds95.command.lua", home);
if (luaL_loadfile(L, path) != LUA_OK) {
fprintf(stderr, "Lua error loading file: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "Lua error running script: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}
lua_getglobal(L, "data_handle");
if (lua_isfunction(L, -1)) {
lua_pushstring(L, str);
if (lua_pcall(L, 1, 1, 0) == LUA_OK) {
if (lua_isstring(L, -1) && cmd_output) {
const char *res = lua_tostring(L, -1);
strcpy(cmd_output, res);
}
lua_pop(L, 1);
} else {
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else if (lua_isstring(L, -1)) {
if (cmd_output) strcpy(cmd_output, lua_tostring(L, -1));
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);
}
}
void lua_group(RDSGroup* group) {
char path[128];
const char *home = getenv("HOME");
if (!home) return;
snprintf(path, sizeof(path), "%s/.rds95.command.lua", home);
if (luaL_loadfile(L, path) != LUA_OK) {
fprintf(stderr, "Lua error loading file: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "Lua error running script: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
return;
}
lua_getglobal(L, "group");
if (lua_isfunction(L, -1)) {
lua_pushinteger(L, group->b);
lua_pushinteger(L, group->c);
lua_pushinteger(L, group->d);
if (lua_pcall(L, 3, 3, 0) == LUA_OK) {
group->d = luaL_checkinteger(L, -1);
group->c = luaL_checkinteger(L, -2);
group->b = luaL_checkinteger(L, -3);
lua_pop(L, 3);
} else {
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else {
lua_pop(L, 1);
}
}
@@ -546,9 +601,6 @@ void lua_call_function(const char* function) {
return;
}
lua_pushnil(L); // Make sure the script doesn't parse any old command
lua_setglobal(L, "data");
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
const char *err = lua_tostring(L, -1);
fprintf(stderr, "Lua error running script: %s\n", err);
@@ -560,7 +612,7 @@ void lua_call_function(const char* function) {
if (lua_isfunction(L, -1)) {
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
fprintf(stderr, "Lua error running 'on_init': %s\n", lua_tostring(L, -1));
fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else lua_pop(L, 1);

View File

@@ -8,5 +8,6 @@
void init_lua(RDSModulator* rds_mod);
void run_lua(char *str, char *cmd_output);
void lua_group(RDSGroup* group);
void lua_call_function(const char* function);
void destroy_lua();

View File

@@ -28,6 +28,7 @@ void get_rds_eon_group(RDSEncoder* enc, RDSGroup *group);
void get_rds_ert_group(RDSEncoder* enc, RDSGroup *group);
uint8_t get_rds_custom_groups(RDSEncoder* enc, RDSGroup *group);
uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group);
void get_rdsp_lua_group(RDSGroup *group);
#define HANDLE_UDG_STREAM(chan_idx, udg_prefix) \
do { \
@@ -108,6 +109,9 @@ static void get_rds_sequence_group(RDSEncoder* enc, RDSGroup *group, char* grp,
case 'T':
get_rds_fasttuning_group(enc, group);
break;
case 'L':
get_rdsp_lua_group(group);
break;
case 'U':
if(enc->state[enc->program].af_oda == 0) get_rds_oda_af_group(enc, group);
else get_rdsp_oda_af_oda_group(group);
@@ -153,6 +157,7 @@ static void get_rds_group(RDSEncoder* enc, RDSGroup *group, uint8_t stream) {
utc = gmtime(&now);
if (utc->tm_min != enc->state[enc->program].last_minute) {
lua_call_function("tick");
enc->state[enc->program].last_minute = utc->tm_min;
uint8_t eon_has_ta = 0;

View File

@@ -1,5 +1,6 @@
#include "rds.h"
#include "lib.h"
#include "lua_rds.h"
uint16_t get_next_af(RDSEncoder* enc) {
uint16_t out;
@@ -364,4 +365,8 @@ uint8_t get_rds_custom_groups2(RDSEncoder* enc, RDSGroup *group) {
return 1;
}
return 0;
}
void get_rdsp_lua_group(RDSGroup *group) {
lua_group(group);
group->is_type_b = (IS_TYPE_B(group->b) != 0);
}