Fix(lua.c): Accept config.lua/.lush files

This commit is contained in:
Cormac Shannon
2026-03-17 18:59:49 +00:00
parent 8b1b3578ed
commit 635569961e

15
lua.c
View File

@@ -4,6 +4,7 @@
** See Copyright Notice in lua.h
*/
#include <unistd.h> // this is unix/linux only
#define lua_c
#include "lprefix.h"
@@ -767,7 +768,9 @@ static void run_config_dir (lua_State *L, const char *dirpath) {
/* collect .lua filenames */
while ((entry = readdir(d)) != NULL && count < 256) {
size_t len = strlen(entry->d_name);
if (len > 4 && strcmp(entry->d_name + len - 4, ".lua") == 0)
if (len > 4 && (
strcmp(entry->d_name + len - 4, ".lua") == 0 ||
strcmp(entry->d_name + len - 5, ".lush") == 0))
names[count++] = strdup(entry->d_name);
}
closedir(d);
@@ -788,20 +791,24 @@ static void run_config_dir (lua_State *L, const char *dirpath) {
static void handle_lushconfig (lua_State *L) {
char configdir[PATH_MAX];
char path[PATH_MAX];
static const char *extensions[] = {"lua", "lush", NULL };
int i;
if (get_config_dir(configdir, sizeof(configdir)) == NULL)
return; /* no HOME or XDG_CONFIG_HOME — skip silently */
/* 1. Run ~/.config/lush/config if it exists */
snprintf(path, sizeof(path), "%s/config", configdir);
/* 1. Run config.lua, or config.lush if any exist */
for (i = 0; extensions[i] != NULL; i++) {
snprintf(path, sizeof(path), "%s/config.%s", configdir, extensions[i]);
if (access(path, R_OK) == 0)
dofile(L, path); /* errors are reported but not fatal */
}
/* 2. Run config.d/ lua files in sorted order */
snprintf(path, sizeof(path), "%s/config.d", configdir);
run_config_dir(L, path);
}
/* }================================================================== */