diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-07-25 10:58:33 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-07-25 10:58:33 +0200 |
commit | 8bb55a25830c3f7d2c67c8571786b6806fb8f515 (patch) | |
tree | 9ff9531f33c82fa1dd23695982c8d1f53dcbd1ad /src/BLua.cc | |
parent | b92f0cee87ae48608c279d7192872b83a29b8fc5 (diff) |
Lua now properly yields when an operation throws EAgain.
Diffstat (limited to 'src/BLua.cc')
-rw-r--r-- | src/BLua.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/BLua.cc b/src/BLua.cc index 1ce20e6..62e4010 100644 --- a/src/BLua.cc +++ b/src/BLua.cc @@ -908,3 +908,54 @@ void Balau::LuaHelpersBase::validate(const lua_functypes_t & entry, bool method, } } } + +static char s_signature = 'B'; + +void Balau::LuaHelpersBase::pushContext(Lua & L, std::function<int(Lua & L)> context, Events::BaseEvent * evt) { + L.push(new LuaHelpersBase(context, evt)); + L.push((void *) &s_signature); +} + +bool Balau::LuaHelpersBase::resume(Lua & L) { + if (L.gettop() < 2) + return false; + + if (!L.islightuserdata()) + return false; + + char * sig = (char *) L.touserdata(); + if (sig != &s_signature) + return false; + + L.remove(-1); + + LuaHelpersBase * b = (LuaHelpersBase *) L.touserdata(); + L.remove(-1); + + int r = b->m_context(L); + + delete b; + + if (r < 0) + return true; + + L.resume(r); + + return true; +} + +Balau::Events::BaseEvent * Balau::LuaHelpersBase::getEvent(Lua & L) { + if (L.gettop() < 2) + return NULL; + + if (!L.islightuserdata()) + return NULL; + + char * sig = (char *) L.touserdata(); + if (sig != &s_signature) + return NULL; + + LuaHelpersBase * b = (LuaHelpersBase *) L.touserdata(-2); + + return b->m_evt; +} |