blob: a1c57be2dd97e26ec10c573dc9ea3aaf0ce2b43b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*
* Copyright (c) 2013 Remko Tronçon
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/VCardConvertor.h>
#include <lua.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <Sluift/Lua/LuaUtils.h>
#include <Swiften/Base/ByteArray.h>
using namespace Swift;
VCardConvertor::VCardConvertor() : GenericLuaElementConvertor<VCard>("vcard") {
}
VCardConvertor::~VCardConvertor() {
}
boost::shared_ptr<VCard> VCardConvertor::doConvertFromLua(lua_State* L) {
boost::shared_ptr<VCard> result = boost::make_shared<VCard>();
lua_getfield(L, -1, "photo");
if (lua_isstring(L, -1)) {
size_t len;
const char* data = lua_tolstring(L, -1, &len);
result->setPhoto(createByteArray(data, len));
}
lua_pop(L, 1);
// TODO
return result;
}
void VCardConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<VCard> payload) {
lua_newtable(L);
if (!payload->getPhoto().empty()) {
lua_pushlstring(L,
reinterpret_cast<const char*>(vecptr(payload->getPhoto())),
payload->getPhoto().size());
lua_setfield(L, -2, "photo");
}
}
|