#pragma once #include "objects/annotation.h" #include "objects/base/service.h" #include "lua.h" #include #include struct SleepingThread { lua_State* thread; uint64_t timeYieldedWhen; uint64_t targetTimeMicros; bool active = true; }; class Script; class DEF_INST_SERVICE ScriptContext : public Service { AUTOGEN_PREAMBLE std::vector sleepingThreads; std::map> scriptSources; int lastScriptSourceId = 0; protected: void InitService() override; bool initialized = false; public: ScriptContext(); ~ScriptContext(); lua_State* state; void PushThreadSleep(lua_State* thread, float delay); void RunSleepingThreads(); std::string RegisterScriptSource(std::shared_ptr