Update redbean ProgramDirectory to return a list of previously set directories

This commit is contained in:
Paul Kulchenko 2023-12-16 21:01:09 -08:00
parent 3a8e01a77a
commit 6077932ead
2 changed files with 18 additions and 1 deletions

View file

@ -1603,11 +1603,16 @@ FUNCTIONS
ProgramGid(int) ProgramGid(int)
Same as the -G flag if called from .init.lua for setgid() Same as the -G flag if called from .init.lua for setgid()
ProgramDirectory(str) ProgramDirectory([directory:str]) → {directory, ...}
Same as the -D flag if called from .init.lua for overlaying local Same as the -D flag if called from .init.lua for overlaying local
file system directories. This may be called multiple times. The file system directories. This may be called multiple times. The
first directory programmed is preferred. These currently do not first directory programmed is preferred. These currently do not
show up in the index page listing. show up in the index page listing.
This call also modifies `package.path` value to either prepend
the added directory in front of the default path (if found) or
to append it (in all other cases).
If no directory is provided, then a table with previously set
directories is returned.
ProgramLogMessages(bool) ProgramLogMessages(bool)
Same as the -m flag if called from .init.lua for logging message Same as the -m flag if called from .init.lua for logging message

View file

@ -4564,6 +4564,18 @@ static int LuaProgramBrand(lua_State *L) {
} }
static int LuaProgramDirectory(lua_State *L) { static int LuaProgramDirectory(lua_State *L) {
size_t i;
// if no parameter is provided, then return current directories
if (lua_isnoneornil(L, 1)) {
lua_newtable(L);
if (stagedirs.n) {
for (i = 0; i < stagedirs.n; ++i) {
lua_pushlstring(L, stagedirs.p[i].s, stagedirs.p[i].n);
lua_seti(L, -2, i + 1);
}
}
return 1;
}
struct stat st; struct stat st;
const char *path = luaL_checkstring(L, 1); const char *path = luaL_checkstring(L, 1);
// check to raise a Lua error, to allow it to be handled // check to raise a Lua error, to allow it to be handled