mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-04 23:06:08 +00:00
First working console
This commit is contained in:
@@ -57,8 +57,16 @@ TConsole::TConsole() {
|
||||
Application::GracefullyShutdown();
|
||||
} else if (cmd == "clear" || cmd == "cls") {
|
||||
// TODO: clear screen
|
||||
mLuaEngine.EnqueueScript(mStateId, std::make_shared<std::string>(cmd));
|
||||
} else {
|
||||
while (!mLuaEngine) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
auto Future = mLuaEngine->EnqueueScript(mStateId, std::make_shared<std::string>(cmd));
|
||||
// wait for it to finish
|
||||
while (!Future->Ready) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
mCommandline.write("Result ready.");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -75,4 +83,5 @@ void TConsole::WriteRaw(const std::string& str) {
|
||||
|
||||
void TConsole::InitializeLuaConsole(TLuaEngine& Engine) {
|
||||
Engine.EnsureStateExists(mStateId, "<>");
|
||||
mLuaEngine = &Engine;
|
||||
}
|
||||
|
||||
@@ -41,9 +41,11 @@ void TLuaEngine::operator()() {
|
||||
}
|
||||
}
|
||||
|
||||
void TLuaEngine::EnqueueScript(TLuaStateId StateID, const std::shared_ptr<std::string>& Script) {
|
||||
std::shared_ptr<TLuaResult> TLuaEngine::EnqueueScript(TLuaStateId StateID, const std::shared_ptr<std::string>& Script) {
|
||||
std::unique_lock Lock(mLuaStatesMutex);
|
||||
mLuaStates.at(StateID)->EnqueueScript(Script);
|
||||
TLuaResult Result;
|
||||
beammp_debug("enqueuing script into \"" + StateID + "\"");
|
||||
return mLuaStates.at(StateID)->EnqueueScript(Script);
|
||||
}
|
||||
|
||||
void TLuaEngine::CollectPlugins() {
|
||||
@@ -102,18 +104,21 @@ void TLuaEngine::EnsureStateExists(TLuaStateId StateId, const std::string& Name)
|
||||
TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomic_bool& Shutdown)
|
||||
: mName(Name)
|
||||
, mShutdown(Shutdown) {
|
||||
mState.open_libraries(sol::lib::base);
|
||||
mState = luaL_newstate();
|
||||
luaL_openlibs(mState);
|
||||
Start();
|
||||
}
|
||||
|
||||
void TLuaEngine::StateThreadData::EnqueueScript(const std::shared_ptr<std::string>& Script) {
|
||||
std::shared_ptr<TLuaResult> TLuaEngine::StateThreadData::EnqueueScript(const std::shared_ptr<std::string>& Script) {
|
||||
beammp_debug("enqueuing script into \"" + mName + "\"");
|
||||
std::unique_lock Lock(mStateExecuteQueueMutex);
|
||||
mStateExecuteQueue.push(Script);
|
||||
auto Result = std::make_shared<TLuaResult>();
|
||||
mStateExecuteQueue.push({ Script, Result });
|
||||
return Result;
|
||||
}
|
||||
|
||||
void TLuaEngine::StateThreadData::operator()() {
|
||||
RegisterThreadAuto();
|
||||
RegisterThread(mName);
|
||||
while (!mShutdown) {
|
||||
std::unique_lock Lock(mStateExecuteQueueMutex);
|
||||
if (mStateExecuteQueue.empty()) {
|
||||
@@ -123,7 +128,9 @@ void TLuaEngine::StateThreadData::operator()() {
|
||||
auto S = mStateExecuteQueue.front();
|
||||
mStateExecuteQueue.pop();
|
||||
Lock.unlock();
|
||||
mState.do_string(*S);
|
||||
beammp_debug("Running script");
|
||||
luaL_dostring(mState, S.first->data());
|
||||
S.second->Ready = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
|
||||
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
||||
TLuaEngine LuaEngine(Server, Network);
|
||||
PPSMonitor.SetNetwork(Network);
|
||||
// BROKEN Application::Console().InitializeLuaConsole(LuaEngine);
|
||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
||||
|
||||
// TODO: replace
|
||||
while (!Shutdown) {
|
||||
|
||||
Reference in New Issue
Block a user