Exemplo n.º 1
0
    protected void GenerateOutputs(float[] variableValues)
    {
        //VirtualConsole.Log ("Executing code...");
        string codeToRun = (inTestMode) ? testCodeText : code;

        compiler = new VirtualCompiler(codeToRun);
        for (int i = 0; i < taskInfo.outputs.Length; i++)
        {
            compiler.AddOutputFunction(taskInfo.outputs[i].name);
        }
        for (int i = 0; i < taskInfo.constants.Length; i++)
        {
            compiler.AddInput(taskInfo.constants[i].name, taskInfo.constants[i].value);
        }
        for (int i = 0; i < variableValues.Length; i++)
        {
            compiler.AddInput(taskInfo.variables[i], variableValues[i]);
        }

        //VirtualConsole.LogInputs (inputNames, inputValues);

        List <VirtualFunction> outputs = compiler.Run();

        if (outputs.Count > 0)
        {
            float val = 0;
            if (outputs[0].values.Count > 0)
            {
                val = outputs[0].values[0];
            }
            var func = new Function()
            {
                name = outputs[0].name, value = val
            };
            outputQueue.Enqueue(func);

            VirtualConsole.LogOutput(func.name, func.value);
        }
    }
Exemplo n.º 2
0
    protected void GenerateOutputs(float[] variableValues)
    {
        //VirtualConsole.Log ("Executing code...");
        string codeToRun = (inTestMode) ? testCodeText : code;

        compiler = new VirtualCompiler(codeToRun);

        compiler.availableFuncsWthoutReturnV.Add("testMethod", testMethod);
        compiler.AddOutputFunction("testMethod2");

        for (int i = 0; i < taskInfo.outputs.Length; i++)
        {
            compiler.AddOutputFunction(taskInfo.outputs[i].name);
        }
        for (int i = 0; i < taskInfo.constants.Length; i++)
        {
            compiler.AddInput(taskInfo.constants[i].name, taskInfo.constants[i].value);
        }
        for (int i = 0; i < variableValues.Length; i++)
        {
            compiler.AddInput(taskInfo.variables[i], variableValues[i]);
        }

        //VirtualConsole.LogInputs (inputNames, inputValues);

        List <VirtualFunction> outputs = compiler.Run();

        if (outputs.Count > 0)
        {
            foreach (VirtualFunction vFunc in outputs)
            {
                //object[] mParams = new object[vFunc.values.Count];
                //Array.Copy(vFunc.values.ToArray(), mParams, vFunc.values.Count);
                if (vFunc.delFunc != null)
                {
                    vFunc.delFunc.Invoke(this, null);
                }


                if (vFunc.FunctionWithoutParam != null && vFunc.FunctionWithParam != null)
                {
                    if (vFunc.values.Count <= 1)
                    {
                        vFunc.FunctionWithoutParam.Invoke();
                    }
                    else
                    {
                        string vFuncReturnValue = vFunc.FunctionWithParam.Invoke(vFunc.values[0].ToString());
                    }
                }
            }

            float val = 0;
            if (outputs[0].values.Count > 0 && outputs[0].values[0] is float)
            {
                val = (float)outputs[0].values[0];
            }
            var func = new Function()
            {
                name = outputs[0].name, value = val
            };
            outputQueue.Enqueue(func);

            VirtualConsole.LogOutput(func.name, func.value);
        }
    }