mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-30 16:59:15 +02:00
fix
This commit is contained in:
+17
-7
@@ -43,20 +43,31 @@ static int my_searcher(lua_State *L) {
|
|||||||
#define PREFIX "/etc/rds95/"
|
#define PREFIX "/etc/rds95/"
|
||||||
|
|
||||||
char path[512];
|
char path[512];
|
||||||
snprintf(path, sizeof(path),
|
size_t prefix_len = strlen(PREFIX);
|
||||||
PREFIX "%s.lua",
|
|
||||||
name);
|
|
||||||
|
|
||||||
for (char *p = path + strlen(PREFIX); *p; p++) {
|
// copy prefix
|
||||||
if (*p == '.') *p = '/';
|
snprintf(path, sizeof(path), "%s", PREFIX);
|
||||||
|
|
||||||
|
// copy name into path, converting '.' to '/'
|
||||||
|
size_t name_len = strlen(name);
|
||||||
|
if (prefix_len + name_len + 4 >= sizeof(path)) { // +4 for ".lua"
|
||||||
|
lua_pushfstring(L, "\n\tmodule name too long: %s", name);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < name_len; i++) {
|
||||||
|
path[prefix_len + i] = (name[i] == '.') ? '/' : name[i];
|
||||||
|
}
|
||||||
|
path[prefix_len + name_len] = '\0';
|
||||||
|
|
||||||
|
// now append .lua
|
||||||
|
strcat(path, ".lua");
|
||||||
|
|
||||||
FILE *f = fopen(path, "rb");
|
FILE *f = fopen(path, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
lua_pushfstring(L, "\n\tno file: %s", path);
|
lua_pushfstring(L, "\n\tno file: %s", path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (luaL_loadfile(L, path) == LUA_OK) {
|
if (luaL_loadfile(L, path) == LUA_OK) {
|
||||||
@@ -66,7 +77,6 @@ static int my_searcher(lua_State *L) {
|
|||||||
lua_pushfstring(L, "\n\terror loading: %s", path);
|
lua_pushfstring(L, "\n\terror loading: %s", path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t init_lua(RDSEncoder* _enc) {
|
uint8_t init_lua(RDSEncoder* _enc) {
|
||||||
static int mutex_initialized = 0;
|
static int mutex_initialized = 0;
|
||||||
enc = _enc;
|
enc = _enc;
|
||||||
|
|||||||
Reference in New Issue
Block a user