Merge pull request #827 from MihailRis/update-platform-new-engine-instance

update platform::new_engine_instance
This commit is contained in:
MihailRis 2026-04-07 22:13:53 +03:00 • committed by GitHub
commit b38a373bf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 7 deletions

View file

@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "release-**"]
pull_request:
branches: [ "main", "dev" ]
branches: [ "main", "dev" ]
workflow_call:
inputs:
build_name:

View file

@ -350,6 +350,7 @@ static int l_start_debug_instance(lua::State* L) {
}
}
auto projectPath = lua::isstring(L, 2) ? lua::require_lstring(L, 2) : "";
auto outputPath = lua::isstring(L, 3) ? lua::require_lstring(L, 3) : "";
const auto& paths = engine->getPaths();
std::vector<std::string> args {
@ -362,7 +363,10 @@ static int l_start_debug_instance(lua::State* L) {
args.emplace_back(io::resolve(std::string(projectPath)).string());
}
platform::new_engine_instance(std::move(args));
platform::new_engine_instance(
std::move(args),
outputPath.empty() ? "" : io::resolve(std::string(outputPath))
);
return lua::pushinteger(L, port);
}

View file

@ -15,7 +15,9 @@ static void sigterm_handler(int signum) {
int main(int argc, char** argv) {
#ifdef VC_BUILD_NAME
logger.info() << "build: " << VC_BUILD_NAME;
if constexpr (VC_BUILD_NAME[0]) {
logger.info() << "build: " << VC_BUILD_NAME;
}
#endif
CoreParameters coreParameters;

View file

@ -215,7 +215,9 @@ std::filesystem::path platform::get_executable_path() {
#endif
}
void platform::new_engine_instance(const std::vector<std::string>& args) {
void platform::new_engine_instance(
const std::vector<std::string>& args, std::filesystem::path outputFile
) {
auto executable = get_executable_path();
#ifdef _WIN32
@ -250,6 +252,24 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
auto commandString = toWString(ss.str());
STARTUPINFOW si = { sizeof(si) };
if (!outputFile.empty()) {
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = CreateFileW(
toWString(outputFile.u8string()).data(),
GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
nullptr,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
nullptr
);
if (si.hStdOutput == INVALID_HANDLE_VALUE) {
throw std::runtime_error(
"CreateFileW failed with code: " +
std::to_string(GetLastError())
);
}
}
PROCESS_INFORMATION pi = { 0 };
DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS;
// | CREATE_NO_WINDOW;
@ -280,7 +300,11 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
for (int i = 0; i < args.size(); i++) {
ss << " " << util::quote(args[i]);
}
ss << " >/dev/null &";
if (outputFile.empty()) {
ss << " >/dev/null &";
} else {
ss << " >" << util::quote(outputFile.u8string()) << " &";
}
auto command = ss.str();
logger.info() << command;
@ -302,4 +326,4 @@ bool platform::stdin_has_data() {
fds.events = POLLIN;
return poll(&fds, 1, 0) == 1;
#endif
}
}

View file

@ -18,7 +18,9 @@ namespace platform {
/// @brief Get current process running executable path
std::filesystem::path get_executable_path();
/// @brief Run a separate engine instance with specified arguments
void new_engine_instance(const std::vector<std::string>& args);
void new_engine_instance(
const std::vector<std::string>& args, std::filesystem::path outputFile
);
/// @brief Open URL in web browser
bool open_url(const std::string& url);
/// @brief Check if stdin has input