Exemple #1
0
// --------------------------------------------------------------------
//
bool PhasorCaller::Call(PhasorScript& phasor_state,
                        const std::string& function, const results_t& expected_types,
                        Result& out_result)
{
    if (!phasor_state.FunctionAllowed(function)) return false;

    try
    {
        Manager::ScriptState& state = *phasor_state.state;
        bool found = false;
        out_result = Caller::Call(state, function, &found);

        // The first result matching the expected types is used
        if (!result_set && out_result.size()) {
            size_t nloop = expected_types.size() < out_result.size() ?
                           expected_types.size() : out_result.size();

            bool use_result = true;

            for (size_t i = 0; i < nloop; i++) {
                Manager::MObject& obj = out_result.ReadObject(i);
                if (expected_types[i] != obj.GetType()) {
                    std::unique_ptr<Manager::MObject> converted;
                    if (!obj.ConvertTo(expected_types[i], &converted)) {
                        out_result.Clear();
                        use_result = false;
                        break;
                    } else out_result.Replace(i, std::move(converted));
                }
            }
            return use_result;
        }
    }
    catch (std::exception & e)
    {
        scripts.HandleError(phasor_state, e.what());

    }
    return false;
}