diff options
Diffstat (limited to 'Sluift/ElementConvertors/DOMElementConvertor.cpp')
| -rw-r--r-- | Sluift/ElementConvertors/DOMElementConvertor.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp index bb4256d..fb1f658 100644 --- a/Sluift/ElementConvertors/DOMElementConvertor.cpp +++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp @@ -128,67 +128,72 @@ namespace { if (!attributeName.empty()) { element.setAttribute(attributeName, attributeValue); } } lua_pop(L, 1); // value } } lua_pop(L, 1); // children lua_getfield(L, -1, "children"); if (lua_istable(L, -1)) { int index = Lua::absoluteOffset(L, -1); for (lua_pushnil(L); lua_next(L, index) != 0; ) { if (lua_isstring(L, -1)) { element.addNode(boost::make_shared<XMLTextNode>(lua_tostring(L, -1))); } else if (lua_istable(L, -1)) { element.addNode(boost::make_shared<XMLRawTextNode>(serializeElement(L))); } lua_pop(L, 1); // value } } lua_pop(L, 1); // children return element.serialize(); } } DOMElementConvertor::DOMElementConvertor() { } DOMElementConvertor::~DOMElementConvertor() { } -boost::shared_ptr<Payload> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) { +boost::shared_ptr<Element> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) { if (!lua_istable(L, index) || type != "dom") { return boost::shared_ptr<Payload>(); } return boost::make_shared<RawXMLPayload>(serializeElement(L).c_str()); } boost::optional<std::string> DOMElementConvertor::convertToLua( - lua_State* L, boost::shared_ptr<Payload> payload) { + lua_State* L, boost::shared_ptr<Element> element) { // Serialize payload to XML + boost::shared_ptr<Payload> payload = boost::dynamic_pointer_cast<Payload>(element); + if (!payload) { + return boost::optional<std::string>(); + } + PayloadSerializer* serializer = serializers.getPayloadSerializer(payload); assert(serializer); std::string serializedPayload = serializer->serialize(payload); lua_newtable(L); // Parse the payload again ParserClient parserClient(L); boost::shared_ptr<XMLParser> parser(parsers.createXMLParser(&parserClient)); bool result = parser->parse(serializedPayload); assert(result); // There can only be one element, so stripping the list lua_pushnil(L); lua_next(L, -2); Lua::registerTableToString(L, -1); lua_replace(L, -3); lua_settop(L, -2); return std::string("dom"); } |
Swift