mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
on_start
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user