示例#1
0
/**
 * \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);
    }
  }
}
示例#2
0
/**
* @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);
  }
}
示例#3
0
// 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;
	}
}
示例#4
0
/**
 * @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();
}
示例#5
0
/**
 * \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();
}
示例#6
0
/**
 * \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();
}
示例#7
0
/**
 * \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;
    }
  }
}
示例#8
0
/**
 * @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();
}
示例#9
0
/**
 * @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);
    }
  }
}
示例#10
0
/**
* @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);
}