add yaml serialization library
This commit is contained in:
parent
396fab02b3
commit
c28bfae679
@ -11,7 +11,7 @@ Subsections:
|
||||
- [Libraries](#)
|
||||
- [app](scripting/builtins/libapp.md)
|
||||
- [base64](scripting/builtins/libbase64.md)
|
||||
- [bjson, json, toml](scripting/filesystem.md)
|
||||
- [bjson, json, toml, yaml](scripting/filesystem.md)
|
||||
- [block](scripting/builtins/libblock.md)
|
||||
- [byteutil](scripting/builtins/libbyteutil.md)
|
||||
- [cameras](scripting/builtins/libcameras.md)
|
||||
|
||||
@ -36,6 +36,22 @@ toml.parse(code: str) -> table
|
||||
|
||||
Parses a TOML string into a table.
|
||||
|
||||
## *yaml* library
|
||||
|
||||
The library contains functions for serializing and deserializing tables:
|
||||
|
||||
```python
|
||||
yaml.tostring(object: table) -> str
|
||||
```
|
||||
|
||||
Serializes an object into a YAML string.
|
||||
|
||||
```python
|
||||
yaml.parse(code: str) -> table
|
||||
```
|
||||
|
||||
Parses a YAML string into a table.
|
||||
|
||||
## *bjson* library
|
||||
|
||||
The library contains functions for working with the binary data exchange format [vcbjson](../../specs/binary_json_spec.md).
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
- [Библиотеки](#)
|
||||
- [app](scripting/builtins/libapp.md)
|
||||
- [base64](scripting/builtins/libbase64.md)
|
||||
- [bjson, json, toml](scripting/filesystem.md)
|
||||
- [bjson, json, toml, yaml](scripting/filesystem.md)
|
||||
- [block](scripting/builtins/libblock.md)
|
||||
- [byteutil](scripting/builtins/libbyteutil.md)
|
||||
- [cameras](scripting/builtins/libcameras.md)
|
||||
|
||||
@ -36,6 +36,22 @@ toml.parse(code: str) -> table
|
||||
|
||||
Парсит TOML строку в таблицу.
|
||||
|
||||
## Библиотека yaml
|
||||
|
||||
Библиотека содержит функции для сериализации и десериализации таблиц:
|
||||
|
||||
```python
|
||||
yaml.tostring(object: table) -> str
|
||||
```
|
||||
|
||||
Сериализует объект в YAML строку.
|
||||
|
||||
```python
|
||||
yaml.parse(code: str) -> table
|
||||
```
|
||||
|
||||
Парсит YAML строку в таблицу.
|
||||
|
||||
## Библиотека bjson
|
||||
|
||||
Библиотека содержит функции для работы с двоичным форматом обмена данными [vcbjson](../../specs/binary_json_spec.md).
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
/// int l_function_name(lua::State* L);
|
||||
|
||||
// Libraries
|
||||
extern const luaL_Reg applib[];
|
||||
extern const luaL_Reg audiolib[];
|
||||
extern const luaL_Reg base64lib[];
|
||||
extern const luaL_Reg bjsonlib[];
|
||||
@ -38,7 +39,6 @@ extern const luaL_Reg packlib[];
|
||||
extern const luaL_Reg particleslib[]; // gfx.particles
|
||||
extern const luaL_Reg playerlib[];
|
||||
extern const luaL_Reg quatlib[];
|
||||
extern const luaL_Reg applib[];
|
||||
extern const luaL_Reg text3dlib[]; // gfx.text3d
|
||||
extern const luaL_Reg timelib[];
|
||||
extern const luaL_Reg tomllib[];
|
||||
@ -48,6 +48,7 @@ extern const luaL_Reg vec3lib[]; // vecn.cpp
|
||||
extern const luaL_Reg vec4lib[]; // vecn.cpp
|
||||
extern const luaL_Reg weatherlib[];
|
||||
extern const luaL_Reg worldlib[];
|
||||
extern const luaL_Reg yamllib[];
|
||||
|
||||
// Components
|
||||
extern const luaL_Reg skeletonlib[];
|
||||
|
||||
@ -19,4 +19,5 @@ static int l_json_parse(lua::State* L) {
|
||||
const luaL_Reg jsonlib[] = {
|
||||
{"tostring", lua::wrap<l_json_stringify>},
|
||||
{"parse", lua::wrap<l_json_parse>},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
20
src/logic/scripting/lua/libs/libyaml.cpp
Normal file
20
src/logic/scripting/lua/libs/libyaml.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "coders/yaml.hpp"
|
||||
#include "api_lua.hpp"
|
||||
|
||||
static int l_stringify(lua::State* L) {
|
||||
auto value = lua::tovalue(L, 1);
|
||||
auto string = yaml::stringify(value);
|
||||
return lua::pushstring(L, string);
|
||||
}
|
||||
|
||||
static int l_parse(lua::State* L) {
|
||||
auto string = lua::require_string(L, 1);
|
||||
auto element = yaml::parse("[string]", string);
|
||||
return lua::pushvalue(L, element);
|
||||
}
|
||||
|
||||
const luaL_Reg yamllib[] = {
|
||||
{"tostring", lua::wrap<l_stringify>},
|
||||
{"parse", lua::wrap<l_parse>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@ -56,6 +56,7 @@ static void create_libs(State* L, StateType stateType) {
|
||||
openlib(L, "vec2", vec2lib);
|
||||
openlib(L, "vec3", vec3lib);
|
||||
openlib(L, "vec4", vec4lib);
|
||||
openlib(L, "yaml", yamllib);
|
||||
|
||||
if (stateType == StateType::SCRIPT) {
|
||||
openlib(L, "app", applib);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user