Esempio n. 1
0
 /// <summary>
 /// Call script function or skip with no error if function not exists.
 /// </summary>
 /// <returns>Execution error.</returns>
 /// <param name="funcName">Function name.</param>
 /// <param name="result">Result of function execution.</param>
 /// <param name="param1">Optional parameter to function.</param>
 /// <param name="param2">Optional parameter to function.</param>
 /// <param name="param3">Optional parameter to function.</param>
 /// <param name="param4">Optional parameter to function.</param>
 public string CallFunctionOrSkip(string funcName, out ScriptVar result,
                                  ScriptVar?param1 = null, ScriptVar?param2 = null,
                                  ScriptVar?param3 = null, ScriptVar?param4 = null)
 {
     if (!_vm.IsFunctionExists(funcName))
     {
         result = new ScriptVar();
         return(null);
     }
     return(_vm.CallFunction(funcName, out result, param1, param2, param3, param4));
 }
Esempio n. 2
0
        /// <summary>
        /// Call script function.
        /// </summary>
        /// <returns>Execution error.</returns>
        /// <param name="funcName">Function name.</param>
        /// <param name="result">Result of function execution.</param>
        /// <param name="param1">Optional parameter to function.</param>
        /// <param name="param2">Optional parameter to function.</param>
        /// <param name="param3">Optional parameter to function.</param>
        /// <param name="param4">Optional parameter to function.</param>
        public string CallFunction(string funcName, out ScriptVar result,
                                   ScriptVar?param1 = null, ScriptVar?param2 = null,
                                   ScriptVar?param3 = null, ScriptVar?param4 = null)
        {
            var undef = new ScriptVar();

            if (InFunctionCall)
            {
                result = undef;
                return("already in function call");
            }
            if (!_parser.Vars.IsFunctionExists(funcName))
            {
                result = undef;
                return(string.Format("function '{0}' not found", funcName));
            }
            InFunctionCall = true;
            var func = _parser.Vars.GetFunction(funcName);

            _scanner.PC = func.Pc;
            _parser.Vars.ResetVars();
            var id  = 0;
            var max = func.Params != null ? func.Params.Length : 0;

            if (param1 != null && id < max)
            {
                _parser.Vars.RegisterVar(func.Params[id++], param1.Value);
            }
            if (param2 != null && id < max)
            {
                _parser.Vars.RegisterVar(func.Params[id++], param2.Value);
            }
            if (param3 != null && id < max)
            {
                _parser.Vars.RegisterVar(func.Params[id++], param3.Value);
            }
            if (param4 != null && id < max)
            {
                _parser.Vars.RegisterVar(func.Params[id++], param4.Value);
            }
            for (; id < max; id++)
            {
                _parser.Vars.RegisterVar(func.Params[id], undef);
            }
            var err = _parser.CallFunction();

            result         = _parser.RetVal;
            InFunctionCall = false;
            return(err);
        }
Esempio n. 3
0
 /// <summary>
 /// Call script function.
 /// </summary>
 /// <returns>Execution error.</returns>
 /// <param name="funcName">Function name.</param>
 /// <param name="result">Result of function execution.</param>
 /// <param name="param1">Optional parameter to function.</param>
 /// <param name="param2">Optional parameter to function.</param>
 /// <param name="param3">Optional parameter to function.</param>
 /// <param name="param4">Optional parameter to function.</param>
 public string CallFunction(string funcName, out ScriptVar result,
                            ScriptVar?param1 = null, ScriptVar?param2 = null,
                            ScriptVar?param3 = null, ScriptVar?param4 = null)
 {
     return(_vm.CallFunction(funcName, out result, param1, param2, param3, param4));
 }
Esempio n. 4
0
 /// <summary>
 /// Create / update script variable with value.
 /// </summary>
 /// <param name="varName">Variable name.</param>
 /// <param name="v">V.</param>
 public void RegisterVar(string varName, ScriptVar v)
 {
     _vars[varName] = v;
 }