#pragma once #include "util/runstateowner.h" #include "g3d/Array.h" #include "boost/any.hpp" #include "boost/shared_ptr.hpp" #include "lua/luabridge.h" #include "script/threadref.h" #include #include struct lua_State; class ThreadInfo; namespace RBX { class Instance; class ScriptContext; namespace Lua { class YieldingThreads { ScriptContext* context; struct WaitingThread { boost::intrusive_ptr thread; RBX::Time waitTime; RBX::Time resumeTime; WaitingThread(lua_State *L, RBX::Time::Interval requestedDelay) :thread(new WeakThreadRef(L)), waitTime(RBX::Time::now()) { resumeTime = waitTime + requestedDelay; } bool operator <(const WaitingThread& other) const { return this->resumeTime > other.resumeTime; } }; typedef std::priority_queue< WaitingThread > WaitThreadRefs; // Lua refs to threads that are waiting on the event WaitThreadRefs waitingThreads; public: YieldingThreads(ScriptContext* context); // Hooking up consumers: void queueWaiter(lua_State *L); void queueWaiter(lua_State *L, LUA_NUMBER delay); void resume(double wallTime, Time expirationTime, bool& throttling); std::size_t waiterCount() const; private: friend class ScriptContext; void clearAllSinks(); }; // specialization template<> int Bridge::on_tostring(const rbx::signals::connection& object, lua_State *L); template<> int Bridge >::on_tostring(const boost::intrusive_ptr& object, lua_State *L); template<> int Bridge< shared_ptr >::on_tostring(const shared_ptr& object, lua_State *L); template<> int Bridge< shared_ptr >::on_tostring(const shared_ptr& object, lua_State *L); } }