diff options
Diffstat (limited to 'Sluift/ElementConvertors/DiscoItemsConvertor.cpp')
| -rw-r--r-- | Sluift/ElementConvertors/DiscoItemsConvertor.cpp | 84 | 
1 files changed, 42 insertions, 42 deletions
| diff --git a/Sluift/ElementConvertors/DiscoItemsConvertor.cpp b/Sluift/ElementConvertors/DiscoItemsConvertor.cpp index a01fa7e..32cbb6e 100644 --- a/Sluift/ElementConvertors/DiscoItemsConvertor.cpp +++ b/Sluift/ElementConvertors/DiscoItemsConvertor.cpp @@ -22,49 +22,49 @@ DiscoItemsConvertor::~DiscoItemsConvertor() {  }  boost::shared_ptr<DiscoItems> DiscoItemsConvertor::doConvertFromLua(lua_State* L) { -	boost::shared_ptr<DiscoItems> result = boost::make_shared<DiscoItems>(); -	if (boost::optional<std::string> value = Lua::getStringField(L, -1, "node")) { -		result->setNode(*value); -	} -	lua_getfield(L, -1, "items"); -	if (lua_istable(L, -1)) { -		for (lua_pushnil(L); lua_next(L, -2); ) { -			result->addItem(DiscoItems::Item( -					Lua::getStringField(L, -1, "name").get_value_or(""), -					JID(Lua::getStringField(L, -1, "jid").get_value_or("")), -					Lua::getStringField(L, -1, "node").get_value_or(""))); -			lua_pop(L, 1); -		} -	} -	lua_pop(L, 1); -	return result; +    boost::shared_ptr<DiscoItems> result = boost::make_shared<DiscoItems>(); +    if (boost::optional<std::string> value = Lua::getStringField(L, -1, "node")) { +        result->setNode(*value); +    } +    lua_getfield(L, -1, "items"); +    if (lua_istable(L, -1)) { +        for (lua_pushnil(L); lua_next(L, -2); ) { +            result->addItem(DiscoItems::Item( +                    Lua::getStringField(L, -1, "name").get_value_or(""), +                    JID(Lua::getStringField(L, -1, "jid").get_value_or("")), +                    Lua::getStringField(L, -1, "node").get_value_or(""))); +            lua_pop(L, 1); +        } +    } +    lua_pop(L, 1); +    return result;  }  void DiscoItemsConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<DiscoItems> payload) { -	lua_newtable(L); -	if (!payload->getNode().empty()) { -		lua_pushstring(L, payload->getNode().c_str()); -		lua_setfield(L, -2, "node"); -	} -	const std::vector<DiscoItems::Item>& items = payload->getItems(); -	if (!items.empty()) { -		lua_createtable(L, boost::numeric_cast<int>(items.size()), 0); -		for (size_t i = 0; i < items.size(); ++i) { -			lua_createtable(L, 0, 0); -			if (!items[i].getName().empty()) { -				lua_pushstring(L, items[i].getName().c_str()); -				lua_setfield(L, -2, "name"); -			} -			if (!items[i].getNode().empty()) { -				lua_pushstring(L, items[i].getNode().c_str()); -				lua_setfield(L, -2, "node"); -			} -			if (items[i].getJID().isValid()) { -				lua_pushstring(L, items[i].getJID().toString().c_str()); -				lua_setfield(L, -2, "jid"); -			} -			lua_rawseti(L, -2, boost::numeric_cast<int>(i+1)); -		} -		lua_setfield(L, -2, "items"); -	} +    lua_newtable(L); +    if (!payload->getNode().empty()) { +        lua_pushstring(L, payload->getNode().c_str()); +        lua_setfield(L, -2, "node"); +    } +    const std::vector<DiscoItems::Item>& items = payload->getItems(); +    if (!items.empty()) { +        lua_createtable(L, boost::numeric_cast<int>(items.size()), 0); +        for (size_t i = 0; i < items.size(); ++i) { +            lua_createtable(L, 0, 0); +            if (!items[i].getName().empty()) { +                lua_pushstring(L, items[i].getName().c_str()); +                lua_setfield(L, -2, "name"); +            } +            if (!items[i].getNode().empty()) { +                lua_pushstring(L, items[i].getNode().c_str()); +                lua_setfield(L, -2, "node"); +            } +            if (items[i].getJID().isValid()) { +                lua_pushstring(L, items[i].getJID().toString().c_str()); +                lua_setfield(L, -2, "jid"); +            } +            lua_rawseti(L, -2, boost::numeric_cast<int>(i+1)); +        } +        lua_setfield(L, -2, "items"); +    }  } | 
 Swift
 Swift