From 2c257ae786100c13e664740c38f4b9046b2ecaf8 Mon Sep 17 00:00:00 2001 From: mingm Date: Thu, 6 Aug 2026 00:48:39 +0800 Subject: [PATCH] feat: recursively load .lua files under config/lua - CollectLuaFiles now walks subdirectories of the lua directory so scripts can be organized in subfolders (one file per game, etc.) - Enable bWatchSubtree in DirectoryWatch so file changes in subdirectories trigger hot reload --- src/OSTPlatform/Windows/DirectoryWatch.cpp | 2 +- src/Utils/Config/LuaConfig.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/OSTPlatform/Windows/DirectoryWatch.cpp b/src/OSTPlatform/Windows/DirectoryWatch.cpp index bea136b..a4096a1 100644 --- a/src/OSTPlatform/Windows/DirectoryWatch.cpp +++ b/src/OSTPlatform/Windows/DirectoryWatch.cpp @@ -98,7 +98,7 @@ bool Watch::IssueRead() { impl_->dir.get(), impl_->buffer.data(), static_cast(impl_->buffer.size()), - FALSE, + TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE, &dummy, &impl_->overlapped, diff --git a/src/Utils/Config/LuaConfig.cpp b/src/Utils/Config/LuaConfig.cpp index 905fa12..323e56b 100644 --- a/src/Utils/Config/LuaConfig.cpp +++ b/src/Utils/Config/LuaConfig.cpp @@ -689,11 +689,21 @@ namespace LuaConfig{ if (!std::filesystem::exists(directory, ec) || !std::filesystem::is_directory(directory, ec)) return files; - for (const auto& entry : std::filesystem::directory_iterator(directory, ec)) { - if (ec) break; - if (!entry.is_regular_file()) continue; - if (entry.path().extension() != ".lua") continue; - files.push_back(entry.path().string()); + std::vector pending = { std::filesystem::path(directory) }; + while (!pending.empty()) { + std::filesystem::path current = pending.back(); + pending.pop_back(); + + std::error_code dec; + for (const auto& entry : std::filesystem::directory_iterator(current, dec)) { + if (dec) break; + std::error_code fec; + if (entry.is_directory(fec)) { + pending.push_back(entry.path()); + } else if (entry.is_regular_file(fec) && entry.path().extension() == ".lua") { + files.push_back(entry.path().string()); + } + } } return files; }