Skip to content

Commit 222574d

Browse files
committed
fix: expose all paths to Lua with forward slashes
For `fs::path` the `u8string()` function yields paths in the native OS format with backward slashes on Windows. For consistency with existing forward slash use in PoB Lua code they're now instead exposed as `generic_u8string()` which has consistent separators across platforms.
1 parent 9afb76f commit 222574d

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

engine/core/core_config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool core_config_c::LoadConfig(std::filesystem::path const& cfgName)
158158
auto fileName = cfgName;
159159
fileName.replace_extension(".cfg");
160160

161-
sys->con->Print(fmt::format("Executing {}\n", fileName.u8string()).c_str());
161+
sys->con->Print(fmt::format("Executing {}\n", fileName.generic_u8string()).c_str());
162162

163163
// Read the config file
164164
fileInputStream_c f;
@@ -202,7 +202,7 @@ bool core_config_c::SaveConfig(std::filesystem::path const& cfgName)
202202
auto fileName = cfgName;
203203
fileName.replace_extension(".cfg");
204204

205-
sys->con->Print(fmt::format("Saving {}\n", fileName.u8string()).c_str());
205+
sys->con->Print(fmt::format("Saving {}\n", fileName.generic_u8string()).c_str());
206206

207207
// Open the config file
208208
fileOutputStream_c f;

engine/core/core_image.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool image_c::Save(std::filesystem::path const& fileName)
9191

9292
image_c* image_c::LoaderForFile(IConsole* conHnd, std::filesystem::path const& fileName)
9393
{
94-
auto nameU8 = fileName.u8string();
94+
auto nameU8 = fileName.generic_u8string();
9595
fileInputStream_c in;
9696
if (in.FileOpen(fileName, true)) {
9797
conHnd->Warning("'%s' doesn't exist or cannot be opened", nameU8.c_str());
@@ -161,7 +161,7 @@ bool targa_c::Load(std::filesystem::path const& fileName, std::optional<size_cal
161161
return true;
162162
}
163163

164-
auto nameU8 = fileName.u8string();
164+
auto nameU8 = fileName.generic_u8string();
165165

166166
// Read header
167167
tgaHeader_s hdr;
@@ -286,7 +286,7 @@ bool jpeg_c::Load(std::filesystem::path const& fileName, std::optional<size_call
286286
return true;
287287
}
288288

289-
auto nameU8 = fileName.u8string();
289+
auto nameU8 = fileName.generic_u8string();
290290

291291
std::vector<byte> fileData(in.GetLen());
292292
if (in.Read(fileData.data(), fileData.size())) {

engine/render/r_main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,6 @@ void r_renderer_c::DoScreenshot(image_c* i, int type, const char* ext)
19521952
auto ssPath = std::filesystem::u8path(fmt::format(CFG_DATAPATH "Screenshots/{:%m%d%y_%H%M%S}.{}",
19531953
fmt::localtime(curTime), ext));
19541954

1955-
19561955
// Make folder if it doesn't exist
19571956
std::error_code ec;
19581957
std::filesystem::create_directories(ssPath.parent_path(), ec);
@@ -1965,7 +1964,7 @@ void r_renderer_c::DoScreenshot(image_c* i, int type, const char* ext)
19651964
sys->con->Print("Couldn't write screenshot!\n");
19661965
return;
19671966
}
1968-
sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssPath.u8string()).c_str());
1967+
sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssPath.generic_u8string()).c_str());
19691968
}
19701969

19711970
r_renderer_c::RenderTarget& r_renderer_c::GetDrawRenderTarget()

engine/system/win/sys_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ find_c::~find_c()
139139
std::optional<std::string> BuildGlobPattern(std::filesystem::path const& glob)
140140
{
141141
using namespace std::literals::string_view_literals;
142-
auto globStr = glob.u8string();
142+
auto globStr = glob.generic_u8string();
143143

144144
// Deal with traditional "everything" wildcards.
145145
if (glob == "*" || glob == "*.*") {
@@ -193,7 +193,7 @@ bool GlobMatch(std::optional<std::string> const& globPattern, std::filesystem::p
193193
reOpts.set_case_sensitive(false);
194194
RE2 reGlob{globPattern.value(), reOpts};
195195

196-
auto fileStr = file.u8string();
196+
auto fileStr = file.generic_u8string();
197197
return RE2::FullMatch(fileStr, reGlob);
198198
}
199199

ui_api.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ SG_LUA_CPP_FUN_BEGIN(imgHandleLoad)
425425
}
426426
}
427427
// TODO(LV): should we use u8path throughout here, to support any callers that use paths outside of working directory?
428-
imgHandle->hnd = ui->renderer->RegisterShader(fileName.u8string(), flags);
428+
imgHandle->hnd = ui->renderer->RegisterShader(fileName.generic_u8string(), flags);
429429
return 0;
430430
}
431431
SG_LUA_CPP_FUN_END()
@@ -1246,7 +1246,7 @@ static int l_searchHandleGetFileName(lua_State* L)
12461246
{
12471247
ui_main_c* ui = GetUIPtr(L);
12481248
searchHandle_s* searchHandle = GetSearchHandle(L, ui, "GetFileName", true);
1249-
lua_pushstring(L, searchHandle->find->fileName.u8string().c_str());
1249+
lua_pushstring(L, searchHandle->find->fileName.generic_u8string().c_str());
12501250
return 1;
12511251
}
12521252

@@ -1542,14 +1542,14 @@ static int l_GetTime(lua_State* L)
15421542
static int l_GetScriptPath(lua_State* L)
15431543
{
15441544
ui_main_c* ui = GetUIPtr(L);
1545-
lua_pushstring(L, ui->scriptPath.u8string().c_str());
1545+
lua_pushstring(L, ui->scriptPath.generic_u8string().c_str());
15461546
return 1;
15471547
}
15481548

15491549
static int l_GetRuntimePath(lua_State* L)
15501550
{
15511551
ui_main_c* ui = GetUIPtr(L);
1552-
lua_pushstring(L, ui->sys->basePath.u8string().c_str());
1552+
lua_pushstring(L, ui->sys->basePath.generic_u8string().c_str());
15531553
return 1;
15541554
}
15551555

@@ -1558,7 +1558,7 @@ static int l_GetUserPath(lua_State* L)
15581558
ui_main_c* ui = GetUIPtr(L);
15591559
auto& userPath = ui->sys->userPath;
15601560
if (userPath) {
1561-
lua_pushstring(L, userPath->u8string().c_str());
1561+
lua_pushstring(L, userPath->generic_u8string().c_str());
15621562
return 1;
15631563
}
15641564
return 0;
@@ -1622,7 +1622,7 @@ SG_LUA_CPP_FUN_END()
16221622
static int l_GetWorkDir(lua_State* L)
16231623
{
16241624
ui_main_c* ui = GetUIPtr(L);
1625-
lua_pushstring(L, ui->scriptWorkDir.u8string().c_str());
1625+
lua_pushstring(L, ui->scriptWorkDir.generic_u8string().c_str());
16261626
return 1;
16271627
}
16281628

@@ -1702,9 +1702,10 @@ SG_LUA_CPP_FUN_BEGIN(LoadModule)
17021702
}
17031703

17041704
ui->sys->SetWorkDir(ui->scriptPath);
1705-
int err = luaL_loadfile(L, fileName.u8string().c_str());
1705+
auto fileStr = fileName.generic_u8string();
1706+
int err = luaL_loadfile(L, fileStr.c_str());
17061707
ui->sys->SetWorkDir(ui->scriptWorkDir);
1707-
ui->LExpect(L, err == 0, "LoadModule() error loading '%s' (%d):\n%s", fileName, err, lua_tostring(L, -1));
1708+
ui->LExpect(L, err == 0, "LoadModule() error loading '%s' (%d):\n%s", fileStr.c_str(), err, lua_tostring(L, -1));
17081709
lua_replace(L, 1); // Replace module name with module main chunk
17091710
lua_call(L, n - 1, LUA_MULTRET);
17101711
return lua_gettop(L);
@@ -1724,7 +1725,7 @@ SG_LUA_CPP_FUN_BEGIN(PLoadModule)
17241725
}
17251726

17261727
ui->sys->SetWorkDir(ui->scriptPath);
1727-
int err = luaL_loadfile(L, fileName.u8string().c_str());
1728+
int err = luaL_loadfile(L, fileName.generic_u8string().c_str());
17281729
ui->sys->SetWorkDir(ui->scriptWorkDir);
17291730
if (err) {
17301731
return 1;

ui_main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void ui_main_c::PCall(int narg, int nret)
160160

161161
void ui_main_c::DoError(const char* msg, const char* error)
162162
{
163-
auto scriptStr = scriptName.u8string();
163+
auto scriptStr = scriptName.generic_u8string();
164164
char* errText = AllocStringLen(strlen(msg) + scriptStr.size() + strlen(error) + 30);
165165
sprintf(errText, "--- SCRIPT ERROR ---\n%s '%s':\n%s\n", msg, scriptStr.c_str(), error);
166166
sys->Exit(errText);
@@ -266,11 +266,11 @@ void ui_main_c::ScriptInit()
266266
{
267267
sys->con->PrintFunc("UI Init");
268268

269-
sys->con->Printf("Script: %s\n", scriptName.u8string().c_str());
269+
sys->con->Printf("Script: %s\n", scriptName.generic_u8string().c_str());
270270
if (!scriptPath.empty()) {
271-
sys->con->Printf("Script working directory: %s\n", scriptWorkDir.u8string().c_str());
271+
sys->con->Printf("Script working directory: %s\n", scriptWorkDir.generic_u8string().c_str());
272272
}
273-
sys->video->SetTitle(scriptName.u8string().c_str());
273+
sys->video->SetTitle(scriptName.generic_u8string().c_str());
274274

275275
restartFlag = false;
276276
didExit = false;
@@ -313,7 +313,7 @@ void ui_main_c::ScriptInit()
313313

314314
// Load the script file
315315
sys->SetWorkDir(scriptWorkDir);
316-
err = luaL_loadfile(L, scriptName.filename().u8string().c_str());
316+
err = luaL_loadfile(L, scriptName.filename().generic_u8string().c_str());
317317
if (err) {
318318
DoError("Error loading", lua_tostring(L, -1));
319319
return;

0 commit comments

Comments
 (0)