diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-21 23:26:44 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-21 23:26:44 -0500 |
commit | 36c784589714f4056eeeba7747e7c20a09333b70 (patch) | |
tree | 1f3f88efaba928f08e44c73f94cbe61648d6b7a4 /src | |
parent | 65c866691aaa709fed249e4e8798068a68cfbae0 (diff) | |
download | tanetane-36c784589714f4056eeeba7747e7c20a09333b70.tar.gz tanetane-36c784589714f4056eeeba7747e7c20a09333b70.tar.bz2 tanetane-36c784589714f4056eeeba7747e7c20a09333b70.zip |
Debug commands run inside a coroutine now yay!
Also it turns out you totally don't need the runner thread.
Diffstat (limited to 'src')
-rw-r--r-- | src/script_system.cpp | 21 | ||||
-rw-r--r-- | src/script_system.h | 1 |
2 files changed, 16 insertions, 6 deletions
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) { | |||
201 | 201 | ||
202 | if (!*callable_) { | 202 | if (!*callable_) { |
203 | callable_.reset(); | 203 | callable_.reset(); |
204 | runner_.reset(); | ||
205 | } | 204 | } |
206 | } | 205 | } |
207 | } | 206 | } |
@@ -212,8 +211,7 @@ void ScriptSystem::runScript(std::string mapName, std::string scriptName) { | |||
212 | loadedScripts_.insert(mapName); | 211 | loadedScripts_.insert(mapName); |
213 | } | 212 | } |
214 | 213 | ||
215 | runner_.reset(new sol::thread(sol::thread::create(engine_.lua_state()))); | 214 | callable_.reset(new sol::coroutine(engine_.traverse_get<sol::function>(mapName, scriptName))); |
216 | callable_.reset(new sol::coroutine(runner_->state().traverse_get<sol::function>(mapName, scriptName))); | ||
217 | 215 | ||
218 | if (!*callable_) { | 216 | if (!*callable_) { |
219 | throw std::runtime_error("Error running script: " + mapName + "." + scriptName); | 217 | throw std::runtime_error("Error running script: " + mapName + "." + scriptName); |
@@ -227,14 +225,27 @@ void ScriptSystem::runScript(std::string mapName, std::string scriptName) { | |||
227 | 225 | ||
228 | if (!*callable_) { | 226 | if (!*callable_) { |
229 | callable_.reset(); | 227 | callable_.reset(); |
230 | runner_.reset(); | ||
231 | } | 228 | } |
232 | } | 229 | } |
233 | 230 | ||
234 | void ScriptSystem::runDebugScript(std::string script) { | 231 | void ScriptSystem::runDebugScript(std::string script) { |
235 | auto result = engine_.script(script); | 232 | sol::load_result loaded_script = engine_.load(script); |
233 | |||
234 | callable_.reset(new sol::coroutine(loaded_script)); | ||
235 | |||
236 | if (!*callable_) { | ||
237 | std::cout << "Error running debug command: " << script << std::endl; | ||
238 | return; | ||
239 | } | ||
240 | |||
241 | auto result = (*callable_)(); | ||
236 | if (!result.valid()) { | 242 | if (!result.valid()) { |
237 | sol::error e = result; | 243 | sol::error e = result; |
238 | std::cout << e.what() << std::endl; | 244 | std::cout << e.what() << std::endl; |
245 | return; | ||
246 | } | ||
247 | |||
248 | if (!*callable_) { | ||
249 | callable_.reset(); | ||
239 | } | 250 | } |
240 | } | 251 | } |
diff --git a/src/script_system.h b/src/script_system.h index 686415c..2d099e3 100644 --- a/src/script_system.h +++ b/src/script_system.h | |||
@@ -26,7 +26,6 @@ private: | |||
26 | 26 | ||
27 | Game& game_; | 27 | Game& game_; |
28 | sol::state engine_; | 28 | sol::state engine_; |
29 | std::unique_ptr<sol::thread> runner_; | ||
30 | std::unique_ptr<sol::coroutine> callable_; | 29 | std::unique_ptr<sol::coroutine> callable_; |
31 | std::set<std::string> loadedScripts_; | 30 | std::set<std::string> loadedScripts_; |
32 | }; | 31 | }; |