From 36c784589714f4056eeeba7747e7c20a09333b70 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 21 Feb 2021 23:26:44 -0500 Subject: Debug commands run inside a coroutine now yay! Also it turns out you totally don't need the runner thread. --- src/script_system.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/script_system.cpp') diff --git a/src/script_system.cpp b/src/script_system.cpp index 14d247e..fcc7ab5 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -201,7 +201,6 @@ void ScriptSystem::tick(double dt) { if (!*callable_) { callable_.reset(); - runner_.reset(); } } } @@ -212,8 +211,7 @@ void ScriptSystem::runScript(std::string mapName, std::string scriptName) { loadedScripts_.insert(mapName); } - runner_.reset(new sol::thread(sol::thread::create(engine_.lua_state()))); - callable_.reset(new sol::coroutine(runner_->state().traverse_get(mapName, scriptName))); + callable_.reset(new sol::coroutine(engine_.traverse_get(mapName, scriptName))); if (!*callable_) { throw std::runtime_error("Error running script: " + mapName + "." + scriptName); @@ -227,14 +225,27 @@ void ScriptSystem::runScript(std::string mapName, std::string scriptName) { if (!*callable_) { callable_.reset(); - runner_.reset(); } } void ScriptSystem::runDebugScript(std::string script) { - auto result = engine_.script(script); + sol::load_result loaded_script = engine_.load(script); + + callable_.reset(new sol::coroutine(loaded_script)); + + if (!*callable_) { + std::cout << "Error running debug command: " << script << std::endl; + return; + } + + auto result = (*callable_)(); if (!result.valid()) { sol::error e = result; std::cout << e.what() << std::endl; + return; + } + + if (!*callable_) { + callable_.reset(); } } -- cgit 1.4.1