예제 #1
0
Pothos::Object ProxyBlockEval::lookupOrEvalAsType(const Poco::Dynamic::Var &arg)
{
    //this is not an expression, but a native JSON type
    if (not arg.isString()) return _evalEnv->eval(arg.toString());

    //the expression is an already evaluated property
    const auto expr = arg.extract<std::string>();
    if (_properties.count(expr) != 0) return _properties.at(expr);

    //otherwise the expression must be evaluated
    //with the evaluated properties as global variables
    //use a new eval to avoid poisoning the globals
    Pothos::Util::EvalEnvironment evalEnv;
    for (const auto &pair : _properties)
    {
        //Register can fail for non-primitive types
        //but those are not used in expressions anyway.
        try {evalEnv.registerConstantObj(pair.first, pair.second);}
        catch (...){}
    }
    return evalEnv.eval(expr);
}