示例#1
0
/**
 * @brief Registers a menu into a context (table or a userdata).
 * @param menu_ref Lua ref of the menu to add.
 * @param context_index Index of the table or userdata in the stack.
 */
void LuaContext::add_menu(int menu_ref, int context_index) {

  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);
  }

  menus.push_back(LuaMenuData(menu_ref, context));

  menu_on_started(menu_ref);
}
示例#2
0
/**
 * \brief Registers a menu into a context (table or a userdata).
 *
 * This function can be called safely even while iterating on the menus list.
 *
 * \param menu_ref Lua ref of the menu to add.
 * \param context_index Index of the table or userdata in the stack.
 * \param on_top \c true to place this menu on top of existing one in the
 * same context, \c false to place it behind.
 */
void LuaContext::add_menu(
    const ScopedLuaRef& menu_ref,
    int context_index,
    bool on_top
) {
  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);
  }

  if (on_top) {
    menus.emplace_back(menu_ref, context);
  }
  else {
    menus.emplace_front(menu_ref, context);
  }

  menu_on_started(menu_ref);
}