From 8bb55a25830c3f7d2c67c8571786b6806fb8f515 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 25 Jul 2013 10:58:33 +0200 Subject: Lua now properly yields when an operation throws EAgain. --- src/LuaTask.cc | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/LuaTask.cc') diff --git a/src/LuaTask.cc b/src/LuaTask.cc index fc92cdf..f94a2b4 100644 --- a/src/LuaTask.cc +++ b/src/LuaTask.cc @@ -57,19 +57,32 @@ void Balau::LuaMainTask::Do() { } void Balau::LuaTask::Do() { - try { - m_cell->run(L); - } - catch (GeneralException e) { - m_cell->m_exception = new GeneralException(e); - } - catch (...) { - m_cell->setError(); + while(true) { + try { + if (L.yielded()) + LuaHelpersBase::resume(L); + else + m_cell->run(L); + } + catch (GeneralException e) { + m_cell->m_exception = new GeneralException(e); + } + catch (...) { + m_cell->setError(); + } + if (L.yielded()) { + Events::BaseEvent * evt = LuaHelpersBase::getEvent(L); + IAssert(evt, "We need an event for now here."); + waitFor(evt); + yield(); + continue; + } + if (m_cell->m_detached) + delete m_cell; + else + m_cell->m_event.trigger(); + break; } - if (m_cell->m_detached) - delete m_cell; - else - m_cell->m_event.trigger(); } void Balau::LuaExecCell::exec(LuaMainTask * mainTask) { -- cgit v1.2.3