summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.cpp31
-rw-r--r--Sluift/ElementConvertors/DiscoInfoConvertor.h9
2 files changed, 35 insertions, 5 deletions
diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.cpp b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp
index 2aa4a77..a528211 100644
--- a/Sluift/ElementConvertors/DiscoInfoConvertor.cpp
+++ b/Sluift/ElementConvertors/DiscoInfoConvertor.cpp
@@ -12,11 +12,15 @@
#include <lua.hpp>
+#include <Swiften/Elements/Form.h>
+#include <Sluift/LuaElementConvertors.h>
#include <Sluift/Lua/LuaUtils.h>
using namespace Swift;
-DiscoInfoConvertor::DiscoInfoConvertor() : GenericLuaElementConvertor<DiscoInfo>("disco_info") {
+DiscoInfoConvertor::DiscoInfoConvertor(LuaElementConvertors* convertors) :
+ GenericLuaElementConvertor<DiscoInfo>("disco_info"),
+ convertors(convertors) {
}
DiscoInfoConvertor::~DiscoInfoConvertor() {
@@ -52,7 +56,17 @@ std::shared_ptr<DiscoInfo> DiscoInfoConvertor::doConvertFromLua(lua_State* L) {
}
lua_pop(L, 1);
- // TODO: Extension
+ lua_getfield(L, -1, "extensions");
+ if (lua_istable(L, -1)) {
+ for (lua_pushnil(L); lua_next(L, -2); ) {
+ std::shared_ptr<Form> form = std::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"));
+ if (!!form) {
+ result->addExtension(form);
+ }
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
return result;
}
@@ -100,7 +114,16 @@ void DiscoInfoConvertor::doConvertToLua(lua_State* L, std::shared_ptr<DiscoInfo>
lua_setfield(L, -2, "features");
}
- // TODO: Extension
+ const std::vector<Form::ref>& extensions = payload->getExtensions();
+ if (!extensions.empty()) {
+ lua_createtable(L, boost::numeric_cast<int>(extensions.size()), 0);
+ for (size_t i = 0; i < extensions.size(); ++i) {
+ if (convertors->convertToLuaUntyped(L, extensions[i]) > 0) {
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+ }
+ lua_setfield(L, -2, "extensions");
+ }
}
boost::optional<LuaElementConvertor::Documentation> DiscoInfoConvertor::getDocumentation() const {
@@ -115,5 +138,7 @@ boost::optional<LuaElementConvertor::Documentation> DiscoInfoConvertor::getDocum
" - `type`: string\n"
" - `language`: string\n"
"- `features`: array(string)\n"
+ "- `extensions`: array(table)\n"
+ "- `form`: string @{Form} (Optional)\n"
);
}
diff --git a/Sluift/ElementConvertors/DiscoInfoConvertor.h b/Sluift/ElementConvertors/DiscoInfoConvertor.h
index 34f8237..c1b2910 100644
--- a/Sluift/ElementConvertors/DiscoInfoConvertor.h
+++ b/Sluift/ElementConvertors/DiscoInfoConvertor.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2016 Isode Limited.
+ * Copyright (c) 2013-2017 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -12,13 +12,18 @@
#include <Sluift/GenericLuaElementConvertor.h>
namespace Swift {
+ class LuaElementConvertors;
+
class DiscoInfoConvertor : public GenericLuaElementConvertor<DiscoInfo> {
public:
- DiscoInfoConvertor();
+ DiscoInfoConvertor(LuaElementConvertors* convertors);
virtual ~DiscoInfoConvertor();
virtual std::shared_ptr<DiscoInfo> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE;
virtual void doConvertToLua(lua_State*, std::shared_ptr<DiscoInfo>) SWIFTEN_OVERRIDE;
virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE;
+
+ private:
+ LuaElementConvertors* convertors;
};
}