mirror of
https://github.com/allankoechke/mbs.git
synced 2026-11-29 09:17:52 +00:00
- B1: malformed scientific notation (1e+, 1e-) no longer silently eats the following operator - B2: && and || now consistently return booleans on every path (C-style semantics), instead of leaking the raw operand on the non-short-circuit path - B3: example main.cpp passes the populated context instead of an empty object - B4: give Expr::kind a default initializer to avoid reading an uninitialized enum
23 lines
661 B
C++
23 lines
661 B
C++
#include <iostream>
|
|
#include <mbs/script.hpp>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using mbs::EvalErr;
|
|
using mbs::EvalOk;
|
|
using mbs::eval_true;
|
|
using mbs::eval_val;
|
|
using mbs::test;
|
|
using nlohmann::json;
|
|
|
|
int main() {
|
|
const std::string src = "1+1+@pi";
|
|
json ctx = json::object();
|
|
ctx["pi"] = 3.14;
|
|
const auto r = eval_val(src, ctx);
|
|
std::cout << "Res: " << std::holds_alternative<EvalOk>(r) << std::endl;
|
|
std::cout << "Res: " << std::get<EvalOk>(r).value << std::endl;
|
|
std::cout << "@pi = " << std::get<EvalOk>(eval_val("@pi", ctx)).value << std::endl;
|
|
std::cout << "@pi = " << eval_true("@pi", ctx).value << std::endl;
|
|
return 0;
|
|
} |