diff options
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r-- | Sluift/ElementConvertors/SConscript | 3 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SubjectConvertor.cpp | 35 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SubjectConvertor.h | 25 |
3 files changed, 62 insertions, 1 deletions
diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index 7317ac7..b9bfc22 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -47,6 +47,7 @@ convertors = [ env.File("ForwardedConvertor.cpp"), env.File("MAMResultConvertor.cpp"), env.File("MAMQueryConvertor.cpp"), - env.File("MAMArchivedConvertor.cpp") + env.File("MAMArchivedConvertor.cpp"), + env.File("SubjectConvertor.cpp") ] Return('convertors') diff --git a/Sluift/ElementConvertors/SubjectConvertor.cpp b/Sluift/ElementConvertors/SubjectConvertor.cpp new file mode 100644 index 0000000..29e2c4f --- /dev/null +++ b/Sluift/ElementConvertors/SubjectConvertor.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#include <Sluift/ElementConvertors/SubjectConvertor.h> + +#include <lua.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <Sluift/Lua/LuaUtils.h> + +using namespace Swift; + +SubjectConvertor::SubjectConvertor() : GenericLuaElementConvertor<Subject>("subject") { +} + +SubjectConvertor::~SubjectConvertor() { +} + +boost::shared_ptr<Subject> SubjectConvertor::doConvertFromLua(lua_State* L) { + boost::shared_ptr<Subject> result = boost::make_shared<Subject>(); + if (boost::optional<std::string> value = Lua::getStringField(L, -1, "text")) { + result->setText(*value); + } + return result; +} + +void SubjectConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<Subject> payload) { + lua_createtable(L, 0, 0); + if (!payload->getText().empty()) { + lua_pushstring(L, payload->getText().c_str()); + lua_setfield(L, -2, "text"); + } +} diff --git a/Sluift/ElementConvertors/SubjectConvertor.h b/Sluift/ElementConvertors/SubjectConvertor.h new file mode 100644 index 0000000..4b3716e --- /dev/null +++ b/Sluift/ElementConvertors/SubjectConvertor.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> + +#include <Sluift/GenericLuaElementConvertor.h> +#include <Swiften/Elements/Subject.h> + +namespace Swift { + class LuaElementConvertors; + + class SubjectConvertor : public GenericLuaElementConvertor<Subject> { + public: + SubjectConvertor(); + virtual ~SubjectConvertor(); + + virtual boost::shared_ptr<Subject> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; + virtual void doConvertToLua(lua_State*, boost::shared_ptr<Subject>) SWIFTEN_OVERRIDE; + }; +} |