Skip to content

Commit a334f9c

Browse files
authored
Update redbean ProgramDirectory to return a list of previously set directories (#1021)
1 parent 3315b6e commit a334f9c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tool/net/help.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,11 +1603,16 @@ FUNCTIONS
16031603
ProgramGid(int)
16041604
Same as the -G flag if called from .init.lua for setgid()
16051605

1606-
ProgramDirectory(str)
1606+
ProgramDirectory([directory:str]) → {directory, ...}
16071607
Same as the -D flag if called from .init.lua for overlaying local
16081608
file system directories. This may be called multiple times. The
16091609
first directory programmed is preferred. These currently do not
16101610
show up in the index page listing.
1611+
This call also modifies `package.path` value to either prepend
1612+
the added directory in front of the default path (if found) or
1613+
to append it (in all other cases).
1614+
If no directory is provided, then a table with previously set
1615+
directories is returned.
16111616

16121617
ProgramLogMessages(bool)
16131618
Same as the -m flag if called from .init.lua for logging message

tool/net/redbean.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4580,6 +4580,18 @@ static int LuaProgramBrand(lua_State *L) {
45804580
}
45814581

45824582
static int LuaProgramDirectory(lua_State *L) {
4583+
size_t i;
4584+
// if no parameter is provided, then return current directories
4585+
if (lua_isnoneornil(L, 1)) {
4586+
lua_newtable(L);
4587+
if (stagedirs.n) {
4588+
for (i = 0; i < stagedirs.n; ++i) {
4589+
lua_pushlstring(L, stagedirs.p[i].s, stagedirs.p[i].n);
4590+
lua_seti(L, -2, i + 1);
4591+
}
4592+
}
4593+
return 1;
4594+
}
45834595
struct stat st;
45844596
const char *path = luaL_checkstring(L, 1);
45854597
// check to raise a Lua error, to allow it to be handled

0 commit comments

Comments
 (0)