Ejemplo n.º 1
0
        public ScriptMethod FindMethod(string name)
        {
            ScriptMethod ret = null;

            if (_methods.TryGetValue(name, out ret))
            {
                return(ret);
            }
            ret = _methodPool.GetMethod(name);
            if (ret != null)
            {
                return(ret);
            }
            foreach (var item in _usings)
            {
                ret = item.Value.GetScriptMethod().FindMethod(name);
                if (ret != null)
                {
                    return(ret);
                }
            }
            if (_parent != null)
            {
                ret = _parent.FindMethod(name);
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public static bool Execute(string src, ScriptMethod space, out ScriptValue result)
        {
            result = ScriptValue.NULL;

            var tempSrc = src.Trim();

            // check validity
            var fpbPos = tempSrc.IndexOf(Grammar.FPB);
            int fpePos = tool.GrammarTool.ReadPairSignPos(tempSrc, fpbPos + 1, Grammar.FPB, Grammar.FPE);

            if (fpbPos == -1 || fpbPos >= fpePos)
            {
                return(false);
            }
            if (fpePos != tempSrc.Length - 1)
            {
                return(false);
            }

            var  methodName = tempSrc.Substring(0, fpbPos).Trim();
            var  findMethod = space.FindMethod(methodName);
            bool bMethod    = (findMethod != null) || MethodLibrary.Contains(methodName);

            if (!bMethod)
            {
                return(false);
            }
            var scriptParams = new List <ScriptValue>();
            var srcArgs      = tempSrc.Substring(fpbPos + 1, fpePos - fpbPos - 1).Trim();

            if (!string.IsNullOrEmpty(srcArgs))
            {
                var argArr = tool.GrammarTool.SplitParams(srcArgs);
                for (int i = 0; i < argArr.Count; ++i)
                {
                    var argStr = argArr[i].Trim();
                    if (string.IsNullOrEmpty(argStr))
                    {
                        return(false);
                    }
                    if (!Execute(argStr, space, out result))
                    {
                        if (!ScriptExpression.Execute(argStr, space, out result))
                        {
                            return(false);
                        }
                    }
                    scriptParams.Add(result);
                }
            }
            if (findMethod == null)
            {
                result = MethodLibrary.Execute(methodName, scriptParams);
                return(true);
            }
            bool bReturn = false;

            return(findMethod.Execute(scriptParams, out bReturn, out result));
        }