MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / EvalMathExpression

Function EvalMathExpression

lib/utils/math-helpers.cpp:10–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace advss {
9
10std::variant<double, std::string> EvalMathExpression(const std::string &expr)
11{
12 static auto randomFunc = []() {
13 thread_local std::mt19937 gen(std::random_device{}());
14 thread_local std::uniform_real_distribution<double> dis(0.0,
15 1.0);
16 return dis(gen);
17 };
18
19 exprtk::symbol_table<double> symbolTable;
20 symbolTable.add_function("random", randomFunc);
21
22 exprtk::expression<double> expression;
23 expression.register_symbol_table(symbolTable);
24 exprtk::parser<double> parser;
25
26 if (parser.compile(expr, expression)) {
27 return expression.value();
28 }
29 return std::string(obs_module_text(
30 "AdvSceneSwitcher.math.expressionFail")) +
31 " \"" + expr + "\"";
32}
33
34bool IsValidNumber(const std::string &str)
35{

Callers 3

HandleMathExpressionMethod · 0.85
MathExpressionChangedMethod · 0.85
test-math.cppFile · 0.85

Calls 2

obs_module_textFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected