Merge pull request #994 from MihailRis/fix-xml.tostring

fix xml.tostring
This commit is contained in:
MihailRis 2026-09-27 16:54:11 +03:00 • committed by GitHub
commit 00825f485c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 1 deletions

View file

@ -30,7 +30,7 @@ static int push_xml(lua::State* L, const xml::xmlelement& elem) {
}
static std::unique_ptr<xml::xmlelement> toxml(lua::State* L) {
lua::getfield(L, TAG_ATTR);
lua::requirefield(L, TAG_ATTR);
auto tag = lua::require_lstring(L, -1);
lua::pop(L);
@ -39,6 +39,13 @@ static std::unique_ptr<xml::xmlelement> toxml(lua::State* L) {
for (int i = 0; i < length; i++) {
lua::rawgeti(L, i + 1);
if (lua::isstring(L, -1)) {
auto textElement = std::make_unique<xml::xmlelement>("#");
textElement->set("#", std::string(lua::require_lstring(L, -1)));
elem->add(std::move(textElement));
lua::pop(L);
continue;
}
elem->add(toxml(L));
lua::pop(L);
}