/** * \brief Unregisters all menus associated to a context. * * This function can be called safely even while iterating on the menus list. * * \param context_index Index of a table or userdata containing menus. */ void LuaContext::remove_menus(int context_index) { const void* context; if (lua_type(l, context_index) == LUA_TUSERDATA) { ExportableToLuaPtr* userdata = static_cast<ExportableToLuaPtr*>( lua_touserdata(l, context_index)); context = userdata->get(); } else { context = lua_topointer(l, context_index); } // Some menu:on_finished() callbacks may create menus themselves, // and we don't want those new menus to get removed. for (LuaMenuData& menu: menus) { menu.recently_added = false; } for (LuaMenuData& menu: menus) { ScopedLuaRef menu_ref = menu.ref; if (menu.context == context && !menu.recently_added) { menu.ref.clear(); menu.context = nullptr; menu_on_finished(menu_ref); } } }
/** * @brief Unregisters all existing menus. */ void LuaContext::remove_menus() { std::list<LuaMenuData>::iterator it; for (it = menus.begin(); it != menus.end(); ++it) { int menu_ref = it->ref; menu_on_finished(menu_ref); destroy_ref(menu_ref); } menus.clear(); }
/** * \brief Unregisters all existing menus. * * This function can be called safely even while iterating on the menus list. */ void LuaContext::remove_menus() { std::list<LuaMenuData>::iterator it; for (it = menus.begin(); it != menus.end(); ++it) { int menu_ref = it->ref; if (menu_ref != LUA_REFNIL) { menu_on_finished(menu_ref); destroy_ref(menu_ref); it->ref = LUA_REFNIL; it->context = NULL; } } }
/** * \brief Unregisters all existing menus. * * This function can be called safely even while iterating on the menus list. */ void LuaContext::remove_menus() { // Some menu:on_finished() callbacks may create menus themselves, // and we don't want those new menus to get removed. for (LuaMenuData& menu: menus) { menu.recently_added = false; } for (LuaMenuData& menu: menus) { if (!menu.recently_added) { ScopedLuaRef menu_ref = menu.ref; if (!menu_ref.is_empty()) { menu.ref.clear(); menu.context = nullptr; menu_on_finished(menu_ref); } } } }
/** * @brief Unregisters all menus associated to a context. * @param context_index Index of a table or userdata containing menus. */ void LuaContext::remove_menus(int context_index) { std::list<int> menus_to_remove; const void* context; if (lua_type(l, context_index) == LUA_TUSERDATA) { ExportableToLua** userdata = (ExportableToLua**) lua_touserdata(l, context_index); context = *userdata; } else { context = lua_topointer(l, context_index); } std::list<LuaMenuData>::iterator it; for (it = menus.begin(); it != menus.end(); ++it) { int menu_ref = it->ref; if (it->context == context) { menu_on_finished(menu_ref); menus.erase(it--); destroy_ref(menu_ref); } } }