/** * \brief Unregisters all timers associated to a context. * * This function can be called safely even while iterating on the timer list. * * \param context_index Index of a table or userdata containing timers. */ void LuaContext::remove_timers(int context_index) { std::list<Timer*> timers_to_remove; const void* context; if (lua_type(l, context_index) == LUA_TUSERDATA) { ExportableToLua** userdata = static_cast<ExportableToLua**>( lua_touserdata(l, context_index)); context = *userdata; } else { context = lua_topointer(l, context_index); } std::map<Timer*, LuaTimerData>::iterator it; for (it = timers.begin(); it != timers.end(); ++it) { Timer* timer = it->first; if (it->second.context == context) { if (!timer->is_finished()) { destroy_ref(it->second.callback_ref); } it->second.callback_ref = LUA_REFNIL; timers_to_remove.push_back(timer); } } }
/** * @brief Calls a function stored in the registry with a reference and * releases this reference. * @param callback_ref Reference of the function to call (if LUA_REFNIL, * nothing is done). */ void LuaContext::do_callback(int callback_ref) { if (callback_ref != LUA_REFNIL) { push_callback(callback_ref); call_function(0, 0, "callback"); destroy_ref(callback_ref); } }
// if who is 0, then reference is destroyed void i4_event_handler_private_reference_class::reference(i4_event_handler_class * who) { destroy_ref(); if (who) { ref=who; next=who->first; who->first=this; } }
/** * @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 Destroys immediately all existing menus. */ void LuaContext::destroy_menus() { std::list<LuaMenuData>::iterator it; for (it = menus.begin(); it != menus.end(); ++it) { int menu_ref = it->ref; if (menu_ref != LUA_REFNIL) { destroy_ref(menu_ref); } } menus.clear(); }
/** * \brief Destroys immediately all existing timers. */ void LuaContext::destroy_timers() { std::map<Timer*, LuaTimerData>::iterator it; for (it = timers.begin(); it != timers.end(); ++it) { Timer* timer = it->first; if (!timer->is_finished()) { destroy_ref(it->second.callback_ref); } RefCountable::unref(timer); } timers.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 Destroys immediately all existing timers. */ void LuaContext::destroy_timers() { std::map<Timer*, LuaTimerData>::iterator it; for (it = timers.begin(); it != timers.end(); ++it) { Timer* timer = it->first; if (!timer->is_finished()) { destroy_ref(it->second.callback_ref); } timer->decrement_refcount(); if (timer->get_refcount() == 0) { delete timer; } } timers.clear(); }
/** * @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); } } }
/** * @brief Releases the reference to a Lua callback. * * The callback may then be collected by Lua. * * @param callback_ref reference of the function (if LUA_REFNIL, * nothing is done) */ void LuaContext::cancel_callback(int callback_ref) { destroy_ref(callback_ref); }