Skip to content

Commit 9ee1865

Browse files
authored
Merge pull request #6 from zao/feat/utf8
feat: encode Lua args as UTF-8 instead of ACP
2 parents 7fafc7f + 01d0f78 commit 9ee1865

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Launcher.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,21 @@ bool isDevScript(std::wstring scriptPath)
271271
return scriptPath.compare(nextToLastSlash + 1, finalSlash - 1 - nextToLastSlash, L"src") == 0;
272272
}
273273

274-
std::vector<std::string> ConvertToACP(std::vector<std::wstring> commandLine)
274+
std::vector<std::string> ConvertToUTF8(std::vector<std::wstring> commandLine)
275275
{
276-
std::vector<std::string> commandLineACP;
276+
std::vector<std::string> commandLineUTF8;
277277
if (commandLine.size() > 0)
278278
{
279-
commandLineACP.reserve(commandLine.size());
279+
commandLineUTF8.reserve(commandLine.size());
280280
for (const std::wstring &param : commandLine)
281281
{
282-
int dwACPSize = WideCharToMultiByte(CP_ACP, 0, param.c_str(), (int)param.size(), NULL, 0, NULL, NULL);
283-
std::string paramACP(dwACPSize, 0);
284-
WideCharToMultiByte(CP_ACP, 0, param.c_str(), (int)param.size(), paramACP.data(), dwACPSize, NULL, NULL);
285-
commandLineACP.emplace_back(std::move(paramACP));
282+
int dwUTF8Size = WideCharToMultiByte(CP_UTF8, 0, param.c_str(), (int)param.size(), NULL, 0, NULL, NULL);
283+
std::string paramUTF8(dwUTF8Size, 0);
284+
WideCharToMultiByte(CP_UTF8, 0, param.c_str(), (int)param.size(), paramUTF8.data(), dwUTF8Size, NULL, NULL);
285+
commandLineUTF8.emplace_back(std::move(paramUTF8));
286286
}
287287
}
288-
return commandLineACP;
288+
return commandLineUTF8;
289289
}
290290

291291
void InitConsole()
@@ -356,18 +356,18 @@ int CALLBACK wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
356356
}
357357

358358
// Create a utf8 version of the commandline parameters
359-
std::vector<std::string> commandLineACP = ConvertToACP(commandLine);
359+
std::vector<std::string> commandLineUTF8 = ConvertToUTF8(commandLine);
360360

361361
// Remove the first commandline argument as the scripts don't care about that.
362-
commandLineACP.erase(commandLineACP.begin());
362+
commandLineUTF8.erase(commandLineUTF8.begin());
363363

364364
// Convert the commandline parameters to a form the DLL can understand
365365
size_t dwTotalParamSize = 0;
366-
for (const std::string &param : commandLineACP)
366+
for (const std::string &param : commandLineUTF8)
367367
{
368368
dwTotalParamSize += param.size() + 1;
369369
}
370-
size_t dwNumParams = commandLineACP.size();
370+
size_t dwNumParams = commandLineUTF8.size();
371371
std::unique_ptr<char[]> pParamBuf = std::make_unique<char[]>(dwTotalParamSize);
372372
char *pCurParamBufLoc = pParamBuf.get();
373373

@@ -376,13 +376,13 @@ int CALLBACK wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
376376
{
377377
ppParamList[i] = pCurParamBufLoc;
378378

379-
const std::string &param = commandLineACP[i];
379+
const std::string &param = commandLineUTF8[i];
380380
memcpy(pCurParamBufLoc, param.c_str(), param.size() + 1);
381381
pCurParamBufLoc += param.size() + 1;
382382
}
383383

384384
// Call into the DLL
385-
int dwStatus = RunLuaFile(dwNumParams, ppParamList.get());
385+
int dwStatus = RunLuaFile((int)dwNumParams, ppParamList.get());
386386

387387
// Cleanup the DLL
388388
FreeLibrary(hDLL);

0 commit comments

Comments
 (0)