mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-04-24 04:36:36 +00:00
fix lua thread never exiting
This commit is contained in:
committed by
Anonymous275
parent
aec6ad9c14
commit
8cd35d64e4
@@ -34,6 +34,8 @@ private:
|
|||||||
TTCPServer& mTCPServer;
|
TTCPServer& mTCPServer;
|
||||||
TUDPServer& mUDPServer;
|
TUDPServer& mUDPServer;
|
||||||
TServer& mServer;
|
TServer& mServer;
|
||||||
|
std::string mPath;
|
||||||
|
bool mShutdown { false };
|
||||||
TSetOfLuaFile mLuaFiles;
|
TSetOfLuaFile mLuaFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "TLuaFile.h"
|
#include "TLuaFile.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -17,12 +18,34 @@ TLuaEngine::TLuaEngine(TServer& Server, TTCPServer& TCPServer, TUDPServer& UDPSe
|
|||||||
fs::create_directory(Path);
|
fs::create_directory(Path);
|
||||||
}
|
}
|
||||||
FolderList(Path, false);
|
FolderList(Path, false);
|
||||||
|
mPath = Path;
|
||||||
|
Application::RegisterShutdownHandler([&] { mShutdown = true; });
|
||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TLuaEngine::operator()() {
|
void TLuaEngine::operator()() {
|
||||||
info("Lua system online");
|
info("Lua system online");
|
||||||
// thread main
|
while (!mShutdown) {
|
||||||
|
if (!mLuaFiles.empty()) {
|
||||||
|
for (auto& Script : mLuaFiles) {
|
||||||
|
struct stat Info { };
|
||||||
|
if (stat(Script->GetFileName().c_str(), &Info) != 0) {
|
||||||
|
Script->SetStopThread(true);
|
||||||
|
mLuaFiles.erase(Script);
|
||||||
|
info(("[HOTSWAP] Removed removed script due to delete"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Script->GetLastWrite() != fs::last_write_time(Script->GetFileName())) {
|
||||||
|
Script->SetStopThread(true);
|
||||||
|
info(("[HOTSWAP] Updated Scripts due to edit"));
|
||||||
|
Script->SetLastWrite(fs::last_write_time(Script->GetFileName()));
|
||||||
|
Script->Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FolderList(mPath, true);
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<TLuaFile>> TLuaEngine::GetScript(lua_State* L) {
|
std::optional<std::reference_wrapper<TLuaFile>> TLuaEngine::GetScript(lua_State* L) {
|
||||||
|
|||||||
Reference in New Issue
Block a user