void LuaEventQueueBase::Emit() { if (!m_events.size()) return; lua_State *l = Pi::luaManager->GetLuaState(); LUA_DEBUG_START(l); lua_getfield(l, LUA_REGISTRYINDEX, "PiEventQueue"); assert(lua_istable(l, -1)); lua_getfield(l, -1, m_name); assert(lua_istable(l, -1)); while (m_events.size()) { LuaEventBase *e = m_events.front(); m_events.pop_front(); lua_pushnil(l); while (lua_next(l, -2) != 0) { int top = lua_gettop(l); PrepareLuaStack(l, e); pi_lua_protected_call(l, lua_gettop(l) - top, 0); } delete e; } lua_pop(l, 2); LUA_DEBUG_END(l, 0); }
inline void LuaEventQueueBase::DoEventCall(lua_State *l, LuaEventBase *e) { if (m_debugTimer) { int top = lua_gettop(l); lua_pushvalue(l, -1); lua_Debug ar; lua_getinfo(l, ">S", &ar); PrepareLuaStack(l, e); Uint32 start = SDL_GetTicks(); pi_lua_protected_call(l, lua_gettop(l) - top, 0); Uint32 end = SDL_GetTicks(); Pi::luaConsole->AddOutput(stringf("DEBUG: %0 %1{u}ms %2:%3{d}", m_name, end-start, ar.source, ar.linedefined)); } else { int top = lua_gettop(l); PrepareLuaStack(l, e); pi_lua_protected_call(l, lua_gettop(l) - top, 0); } }
void LuaEventQueueBase::EmitSingleEvent(LuaEventBase *e) { lua_State *l = Pi::luaManager->GetLuaState(); LUA_DEBUG_START(l); lua_getfield(l, LUA_REGISTRYINDEX, "PiEventQueue"); assert(lua_istable(l, -1)); lua_getfield(l, -1, m_name); assert(lua_istable(l, -1)); lua_pushnil(l); while (lua_next(l, -2) != 0) { int top = lua_gettop(l); PrepareLuaStack(l, e); pi_lua_protected_call(l, lua_gettop(l) - top, 0); } lua_pop(l, 2); LUA_DEBUG_END(l, 0); delete e; }