diff options
author | Nicolas Noble <pixel@nobis-crew.org> | 2013-08-07 15:07:19 -0700 |
---|---|---|
committer | Nicolas Noble <pixel@nobis-crew.org> | 2013-08-07 15:07:19 -0700 |
commit | 06c4d6a7bca960a163cf45d37cc5f42684d6840d (patch) | |
tree | 0e3e8e7edaa3f20b9d81b7a51f8e950dafe88421 /src | |
parent | e1f011cbce057e0d4452f8c91329afa1ac3a80a3 (diff) |
Deferring object collection in Lua because yielding from the garbage collector is a very bad idea.
Diffstat (limited to 'src')
-rw-r--r-- | src/BLua.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/BLua.cc b/src/BLua.cc index 73995c0..3d47c72 100644 --- a/src/BLua.cc +++ b/src/BLua.cc @@ -5,6 +5,8 @@ #include "Input.h" #include "Buffer.h" #include "HelperTasks.h" +#include "StacklessTask.h" +#include "TaskMan.h" extern "C" { #include <lualib.h> @@ -267,10 +269,26 @@ int Balau::LuaStatics::callwrap(lua_State * __L, lua_CFunction func) { return r; } +namespace { + +class CollectorTask : public Balau::StacklessTask { + public: + CollectorTask(Balau::LuaObjectBase * obj) : m_obj(obj) { } + private: + virtual const char * getName() const override { return "CollectorTask"; } + virtual void Do() override { delete m_obj; } + Balau::LuaObjectBase * m_obj; +}; + +}; + int Balau::LuaStatics::collector(lua_State * __L) { Lua L(__L); LuaObjectBase * o = (LuaObjectBase *) L.touserdata(); - return L.yield(Future<int>([o]() { o->destroy(); return 0; })); + Task * collector = o->spawnCollector(); + if (collector) + TaskMan::registerTask(collector); + return 0; } int Balau::LuaStatics::destructor(lua_State * __L) { |