Crates.io | oml |
lib.rs | oml |
version | 0.0.6 |
source | src |
created_at | 2024-07-16 14:37:30.994828 |
updated_at | 2024-09-04 16:14:29.254709 |
description | Open Markup Language! |
homepage | https://github.com/fawdlstty/oml |
repository | https://github.com/fawdlstty/oml |
max_upload_size | |
id | 1305122 |
size | 83,579 |
English | 简体中文
Open Markup Language! A dynamic configuration scripting language that can embed script code in the configuration file to achieve dynamic configuration update.
Install: Run cargo add oml
in the project directory
fn main() {
let oml_str = r#"
[hello]
value = 12
name = $"hello world {value + 12}"
"#;
let mut root = OmlExpr::from_str(oml_str).unwrap();
root["hello"]["value"].set_int(30);
let root = root.evalute().unwrap();
println!("{}", root["hello"]["name"].as_str()); // hello world 42
}
#include <iostream>
#include <string>
#include "oml/oml.hpp"
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "ntdll.lib")
#pragma comment(lib, "bcrypt.lib")
#pragma comment(lib, "Userenv.lib")
#pragma comment(lib, "oml.lib")
int main() {
auto oexpr = oml::OmlExpr::from_str(R"(
[hello]
value = 12
name = $"hello world {value + 12}"
)");
if (oexpr.index() == 1) {
auto err = std::get<std::string>(oexpr);
std::cout << err << std::endl;
return 0;
}
auto expr = std::get<oml::OmlExpr>(oexpr);
expr["hello"]["value"].set_int(30);
auto ovalue = expr.evalute();
if (ovalue.index() == 1) {
auto err = std::get<std::string>(ovalue);
std::cout << err << std::endl;
return 0;
}
auto value = std::get<oml::OmlValue>(ovalue);
auto str = value["hello"]["name"].as_str();
std::cout << str << std::endl;
return 0;
}