mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
update xml.parse_vcd
This commit is contained in:
parent
13984539f5
commit
e9221af407
3 changed files with 18 additions and 6 deletions
|
|
@ -101,8 +101,9 @@ xml.tostring(data: XML, multiline: bool = true) -> str
|
||||||
xml.parse(code: str) -> XML
|
xml.parse(code: str) -> XML
|
||||||
|
|
||||||
-- Parses the VCD (VoxelCore Declaration) format used by the VCM format.
|
-- Parses the VCD (VoxelCore Declaration) format used by the VCM format.
|
||||||
-- root_tag - root element tag (the format does not require an explicit root)
|
-- root_tag - a root element with the specified tag will be implicitly created,
|
||||||
xml.parse(code: str, root_tag: str = "root") -> XML
|
-- containing all root elements
|
||||||
|
xml.parse_vcd(code: str, root_tag: str = "root") -> XML
|
||||||
```
|
```
|
||||||
|
|
||||||
## *bjson* library
|
## *bjson* library
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,9 @@ xml.tostring(data: XML, multiline: bool = true) -> str
|
||||||
xml.parse(code: str) -> XML
|
xml.parse(code: str) -> XML
|
||||||
|
|
||||||
-- Парсит формат VCD (VoxelCore Declaration), используемый форматом VCM.
|
-- Парсит формат VCD (VoxelCore Declaration), используемый форматом VCM.
|
||||||
-- root_tag - тег корневого элемента (формат не требует наличия явного)
|
-- root_tag - будет неявно создан корневой элемент с указанным тегом,
|
||||||
xml.parse(code: str, root_tag: str = "root") -> XML
|
-- содержащий все корневые элементы
|
||||||
|
xml.parse_vcd(code: str, root_tag: str | nil = nil) -> XML
|
||||||
```
|
```
|
||||||
|
|
||||||
## Библиотека bjson
|
## Библиотека bjson
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,19 @@ static int l_parse_vcd(lua::State* L) {
|
||||||
auto string = lua::require_string(L, 1);
|
auto string = lua::require_string(L, 1);
|
||||||
auto rootTag = lua::tostring(L, 2);
|
auto rootTag = lua::tostring(L, 2);
|
||||||
auto document = xml::parse_vcm(
|
auto document = xml::parse_vcm(
|
||||||
"[string]", string, rootTag ? rootTag : DEFAULT_ROOT_TAG
|
"[string]", string, rootTag ? rootTag : ""
|
||||||
);
|
);
|
||||||
return push_xml(L, *document->getRoot());
|
const auto& root = *document->getRoot();
|
||||||
|
if (rootTag != nullptr) {
|
||||||
|
return push_xml(L, root);
|
||||||
|
}
|
||||||
|
int rootElements = root.size();
|
||||||
|
if (rootElements != 1) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"one root element expected, got " + std::to_string(rootElements)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return push_xml(L, *root.getElements()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg xmllib[] = {
|
const luaL_Reg xmllib[] = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue