#pragma once #include "objects/annotation.h" #include "objects/base/service.h" #include "luaapis.h" // IWYU pragma: keep #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; 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(); // Generates an environment with a metatable and pushes it both the env table and metatable in order onto the stack void NewEnvironment(lua_State* state); static inline std::shared_ptr Create() { return std::make_shared(); }; };