Skip to content

Commit 8b8b70b

Browse files
committed
deal with directory separators cleanly
dfhack assumes that scripts are in a namespace in which directories are separated by slashes, and also that pathnames will be slash-separated this enforces that when the transition is made from a `std::filesystem::path` to dfhack's internal script name space, backslashes are replaced with slashes on systems where the preferred separator is not already '/'
1 parent a801e96 commit 8b8b70b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/LuaApi.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,12 @@ static int filesystem_listdir_recursive(lua_State *L)
32073207
lua_pushinteger(L, i++);
32083208
lua_newtable(L);
32093209
lua_pushstring(L, "path");
3210-
lua_pushstring(L, (it->first).string().c_str());
3210+
auto p = (it->first).string();
3211+
if constexpr (std::filesystem::path::preferred_separator != '/')
3212+
{
3213+
std::ranges::replace(p, std::filesystem::path::preferred_separator, '/');
3214+
}
3215+
lua_pushstring(L, p.c_str());
32113216
lua_settable(L, -3);
32123217
lua_pushstring(L, "isdir");
32133218
lua_pushboolean(L, it->second);

0 commit comments

Comments
 (0)