diff --git a/include/openspace/scripting/scriptscheduler.h b/include/openspace/scripting/scriptscheduler.h index 75c45e1e71..e0783d7c27 100644 --- a/include/openspace/scripting/scriptscheduler.h +++ b/include/openspace/scripting/scriptscheduler.h @@ -64,6 +64,8 @@ public: void skipTo(double time); void skipTo(const std::string& timeStr); + void clearSchedule(); + std::queue scheduledScripts(double newTime); std::queue scheduledScripts(const std::string& timeStr); diff --git a/src/scripting/scriptscheduler.cpp b/src/scripting/scriptscheduler.cpp index ef73fb4a13..fa2bd0d03b 100644 --- a/src/scripting/scriptscheduler.cpp +++ b/src/scripting/scriptscheduler.cpp @@ -100,6 +100,10 @@ void ScriptScheduler::skipTo(const std::string& timeStr) { skipTo(SpiceManager::ref().ephemerisTimeFromDate(timeStr)); } +void ScriptScheduler::clearSchedule() { + _scheduledScripts.clear(); + _currentIndex = 0; +} std::queue ScriptScheduler::scheduledScripts(double newTime) { std::queue triggeredScripts; @@ -157,6 +161,15 @@ namespace luascriptfunctions { OsEng.scriptScheduler().skipTo(dateStr); } + + int clear(lua_State* L) { + using ghoul::lua::luaTypeToString; + int nArguments = lua_gettop(L); + if (nArguments != 0) + return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments); + + OsEng.scriptScheduler().clearSchedule(); + } } // namespace luascriptfunction @@ -177,6 +190,12 @@ LuaLibrary ScriptScheduler::luaLibrary() { "string", "skip to a time without executing scripts" }, + { + "clear", + &luascriptfunctions::clear, + "", + "clears all scheduled scripts" + }, } }; }