mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-02-26 20:33:53 +01:00
out len
This commit is contained in:
@@ -549,16 +549,16 @@ void init_lua(RDSModulator* rds_mod) {
|
||||
}
|
||||
}
|
||||
|
||||
void run_lua(char *str, char *cmd_output) {
|
||||
void run_lua(char *str, char *cmd_output, size_t* out_len) {
|
||||
pthread_mutex_lock(&lua_mutex);
|
||||
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) _strncpy(cmd_output, lua_tostring(L, -1), 254);
|
||||
if (lua_isstring(L, -1) && cmd_output) _strncpy(cmd_output, lua_tolstring(L, -1, out_len), 254);
|
||||
} else fprintf(stderr, "Lua error: %s at 'data_handle'\n", lua_tostring(L, -1));
|
||||
} else if (lua_isstring(L, -1) && cmd_output) _strncpy(cmd_output, lua_tostring(L, -1), 254);
|
||||
} else if (lua_isstring(L, -1) && cmd_output) _strncpy(cmd_output, lua_tolstring(L, -1, out_len), 254);
|
||||
lua_pop(L, 1);
|
||||
pthread_mutex_unlock(&lua_mutex);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "modulator.h"
|
||||
|
||||
void init_lua(RDSModulator* rds_mod);
|
||||
void run_lua(char *str, char *cmd_output);
|
||||
void run_lua(char *str, char *cmd_output, size_t* out_len);
|
||||
int lua_group(RDSGroup* group, const char grp);
|
||||
int lua_rds2_group(RDSGroup* group, int stream);
|
||||
void lua_call_function_nolock(const char* function);
|
||||
|
||||
@@ -58,9 +58,9 @@ void poll_udp_server() {
|
||||
strncpy(cmd_buf, token, BUF_SIZE - 1);
|
||||
|
||||
memset(cmd_output, 0, BUF_SIZE);
|
||||
run_lua(cmd_buf, cmd_output);
|
||||
|
||||
size_t out_len = strlen(cmd_output);
|
||||
size_t out_len = 0;
|
||||
run_lua(cmd_buf, cmd_output, &out_len);
|
||||
if (out_len > 0 && sendto(sockfd, cmd_output, out_len, 0, (struct sockaddr *)&client_addr, client_len) == -1) perror("sendto"); // no walrus
|
||||
}
|
||||
token = strtok(NULL, "\r\n");
|
||||
|
||||
Reference in New Issue
Block a user