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