예제 #1
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            List <CQ_Content.Value> list = new List <CQ_Content.Value>();

            foreach (ICQ_Expression p in listParam)
            {
                if (p != null)
                {
                    list.Add(p.ComputeValue(content));
                }
            }
            CQ_Content.Value v = null;

            SType.Function retFunc = null;
            bool           bFind   = false;

            if (content.CallType != null)
            {
                bFind = content.CallType.functions.TryGetValue(funcname, out retFunc);
            }

            if (bFind)
            {
                if (retFunc.bStatic)
                {
                    v = content.CallType.StaticCall(content, funcname, list);
                }
                else
                {
                    v = content.CallType.MemberCall(content, content.CallThis, funcname, list);
                }
            }


            else
            {
                v = content.GetQuiet(funcname);
                if (v != null && v.value is Delegate)
                {
                    //if(v.value is Delegate)
                    {
                        Delegate d = v.value as Delegate;
                        v = new CQ_Content.Value();
                        object[] obja = new object[list.Count];
                        for (int i = 0; i < list.Count; i++)
                        {
                            obja[i] = list[i].value;
                        }
                        v.value = d.DynamicInvoke(obja);
                        if (v.value == null)
                        {
                            v.type = null;
                        }
                        else
                        {
                            v.type = v.value.GetType();
                        }
                    }
                    //else
                    //{
                    //    throw new Exception(funcname + "不是函数");
                    //}
                }
                else
                {
                    v = content.environment.GetFunction(funcname).Call(content, list);
                }
            }
            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(v);
        }
예제 #2
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

            CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count);
            for (int i = 0; i < _expressions.Count; i++)
            {
                parameters[i] = _expressions[i].ComputeValue(content);
            }

            CQ_Value v = CQ_Value.Null;

            Class_CQuark.Function retFunc = null;
            bool bFind = false;
            if (content.CallType != null)
            {
                bFind = content.CallType.functions.TryGetValue(funcname, out retFunc);
            }

            if (bFind)
            {
                if (retFunc.bStatic)
                {
                    v = content.CallType.StaticCall(content, funcname, parameters);
                }
                else
                {
                    v = content.CallType.MemberCall(content, content.CallThis, funcname, parameters);
                }
            }
            else
            {
                v = content.GetQuiet(funcname);
                if (v.IsDelegate)
                {
                    Delegate d = v.GetObject() as Delegate;
                    v = new CQ_Value();
                    object[] obja = new object[parameters.Length];
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        obja[i] = parameters[i].GetObject();
                    }
                    object obj = d.DynamicInvoke(obja);

                    if (obj == null)
                    {
                        v.SetNoneTypeObject(null);
                    }
                    else
                    {
                        v.SetObject(obj.GetType(), obj);
                    }
                }
                else
                {
                    throw new Exception(funcname + "没有这样的方法");
                    //v = CQuark.AppDomain.GetMethod(funcname).Call(content, list);
                }
            }
            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(v);
        }