0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00
This commit is contained in:
2025-12-24 10:54:54 +01:00
parent 979817b292
commit 8bc35536c5
4 changed files with 11 additions and 9 deletions

View File

@@ -22,6 +22,10 @@ function reset_rds() end
---It should be defined by the user in the script.
---@return nil
function on_init() end
---This function is called by the C core after we initialize the encoder (always, every start)
---It should be defined by the user in the script.
---@return nil
function on_start() end
---@param pi integer
function set_rds_pi(pi) end

View File

@@ -6,7 +6,7 @@ static lua_State *L = NULL;
int lua_set_rds_program_defaults(lua_State *localL) {
(void)localL;
set_rds_defaults(mod->enc, mod->enc->program);
lua_on_init();
lua_call_function("on_init");
return 0;
}
@@ -535,7 +535,7 @@ void run_lua(char *str, char *cmd_output) {
}
}
void lua_on_init() {
void lua_call_function(const char* function) {
char path[128];
snprintf(path, sizeof(path), "%s/.rds95.command.lua", getenv("HOME"));
@@ -556,17 +556,14 @@ void lua_on_init() {
return;
}
lua_getglobal(L, "on_init");
lua_getglobal(L, 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));
lua_pop(L, 1);
}
} else {
// printf("Note: 'on_init' function not found in Lua script. Skipping.\n");
lua_pop(L, 1);
}
} else lua_pop(L, 1);
}
void destroy_lua(void) {

View File

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

View File

@@ -381,8 +381,9 @@ void init_rds_encoder(RDSEncoder* enc) {
if (encoder_loadFromFile(enc)) {
printf("Encoder file will be reinitialized.\n");
lua_on_init();
lua_call_function("on_init");
}
encoder_saveToFile(enc);
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(enc, i);
lua_call_function("on_start");
}