public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif object[] list = new object[_expressions.Count - 1]; int count = _expressions[0] == null ? (_expressions.Count - 1) : (int)_expressions[0].ComputeValue(content).GetNumber(); // if(count == 0) // throw new Exception("不能创建0长度数组"); CQ_Value vcount = new CQ_Value(); vcount.SetNumber(typeof(int), count); for (int i = 0; i < _expressions.Count - 1; i++) { list[i] = (_expressions[i + 1].ComputeValue(content).GetObject()); } CQ_Value[] param = new CQ_Value[] { vcount }; CQ_Value outvalue = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.New(type.typeBridge.type, param, out outvalue)) { outvalue = type._class.New(content, param); } object obj = outvalue.GetObject(); for (int i = 0; i < list.Length; i++) { type._class.IndexSet(content, obj, i, list[i]); } #if CQUARK_DEBUG content.OutStack(this); #endif return(outvalue); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } CQ_Value value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 object obj = parent.GetObject(); if (!Wrap.MemberValueGet(parent.m_type, obj, membername, out value)) { IClass iclass = CQuark.AppDomain.GetITypeByCQValue(parent)._class; CQ_ClassInstance s = obj as CQ_ClassInstance; if (s != null) { iclass = s.type; } value = iclass.MemberValueGet(content, obj, membername); } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); //做数学计算 //从上下文取值 //_value = null; //return null; }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); object obj = parent.GetObject(); if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } CQ_Value key = _expressions[1].ComputeValue(content); CQ_Value value = _expressions[2].ComputeValue(content); //object setv=value.value; //if(value.type!=parent.type) //{ // var vtype = CQuark.AppDomain.GetType(value.type); // setv = vtype.ConvertTo(CQuark.AppDomain, setv, parent.type); //} //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.IndexSet(parent.m_type, obj, key, value)) { var type = CQuark.AppDomain.GetITypeByCQValue(parent); type._class.IndexSet(content, parent.GetObject(), obj, value.GetObject()); } CQ_Expression_GetValue f = _expressions[0] as CQ_Expression_GetValue; content.Set(f.value_name, parent); #if CQUARK_DEBUG content.OutStack(this); #endif return(CQ_Value.Null); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); #if CQUARK_DEBUG if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } #endif CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count - 1); for (int i = 0; i < _expressions.Count - 1; i++) { parameters[i] = _expressions[i + 1].ComputeValue(content); } CQ_Value value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 object obj = parent.GetObject(); if (!Wrap.MemberCall(parent.m_type, obj, functionName, parameters, out value)) { //TODO 要么注册所有基本类型(bool,int,string...)要么这里特殊处理 if (functionName == "ToString" && parameters.Length == 0) { CQ_Value ret = new CQ_Value(); ret.SetObject(typeof(string), obj.ToString()); return(ret); } else if (obj is UnityEngine.MonoBehaviour && functionName == "StartCoroutine" && parameters.Length >= 1 && parameters[0].GetObject() is CQ_Expression_Block) { //从西瓜调用的ClassSystem.StartCoroutine(CquarkMethod());不需要走cache UnityEngine.MonoBehaviour mb = obj as UnityEngine.MonoBehaviour; CQ_Expression_Block call = parameters[0].GetObject() as CQ_Expression_Block; CQ_Value ret = new CQ_Value(); ret.SetObject(typeof(UnityEngine.Coroutine), mb.StartCoroutine(call.callObj.CallType.CoroutineCall(call, call.callObj, mb))); return(ret); } else { var iclass = CQuark.AppDomain.GetITypeByCQValue(parent)._class; if (cache == null || cache.cachefail) { cache = new MethodCache(); value = iclass.MemberCall(content, obj, functionName, parameters, cache); } else { value = iclass.MemberCallCache(content, obj, parameters, cache); } } } #if CQUARK_DEBUG content.OutStack(this); #endif CQ_ObjPool.PushArray(parameters); return(value); }
public virtual CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right) { //会走到这里说明不是简单的数学计算了 Type rightType = right.m_type; if (rightType == typeof(string) && code == '+') { CQ_Value returnValue = new CQ_Value(); returnValue.SetObject(typeof(string), left.ToString() + right.ToString()); return(returnValue); } else { CQ_Value returnValue = CQ_Value.Null; MethodInfo call = null; //我们这里开始使用Wrap,如果再不行再走反射 if (code == '+') { if (Wrap.OpAddition(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Addition", new Type[] { this.typeBridge, rightType }); } } else if (code == '-') { if (Wrap.OpSubtraction(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Subtraction", new Type[] { this.typeBridge, rightType }); } } else if (code == '*') { if (Wrap.OpMultiply(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Multiply", new Type[] { this.typeBridge, rightType }); } } else if (code == '/') { if (Wrap.OpDivision(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Division", new Type[] { this.typeBridge, rightType }); } } else if (code == '%') { if (Wrap.OpModulus(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Modulus", new Type[] { this.typeBridge, rightType }); } } //Wrap没走到,走反射 returnValue = new CQ_Value(); returnValue.SetObject(typeBridge.type, call.Invoke(null, new object[] { left.GetObject(), right.GetObject() })); //function.StaticCall(env,"op_Addtion",new List<ICL>{}) return(returnValue); } }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value left = _expressions[0].ComputeValue(content); CQ_Value right = _expressions[1].ComputeValue(content); IType type = CQuark.AppDomain.GetITypeByCQValue(left); CQ_Value val = type.Math2Value(mathop, left, right); //val.SetValue(left.typeBridge, type.ConvertTo(val.GetValue(), left.typeBridge)); left.UsingValue(val); if (_expressions[0] is CQ_Expression_MemberValueGet) { CQ_Expression_MemberValueGet f = _expressions[0] as CQ_Expression_MemberValueGet; CQ_Value parent = f._expressions[0].ComputeValue(content); if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + f._expressions[0].ToString() + ":" + ToString()); } //这几行是为了快速获取Unity的静态变量,而不需要反射 object obj = parent.GetObject(); if (!Wrap.MemberValueSet(parent.m_type, obj, f.membername, val)) { IType ptype = CQuark.AppDomain.GetITypeByCQValue(parent); ptype._class.MemberValueSet(content, obj, f.membername, val); } } else if (_expressions[0] is CQ_Expression_StaticValueGet) { CQ_Expression_StaticValueGet f = _expressions[0] as CQ_Expression_StaticValueGet; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.StaticValueSet(type.typeBridge.type, f.staticmembername, val)) { f.type._class.StaticValueSet(content, f.staticmembername, val); } } else if (_expressions[0] is CQ_Expression_GetValue) { CQ_Expression_GetValue f = _expressions[0] as CQ_Expression_GetValue; content.Set(f.value_name, left); } else if (_expressions[0] is CQ_Expression_IndexGet) { CQ_Expression_IndexGet f = _expressions[0] as CQ_Expression_IndexGet; CQ_Value parent = f._expressions[0].ComputeValue(content); object obj = parent.GetObject(); CQ_Value key = f._expressions[1].ComputeValue(content); IType parenttype = CQuark.AppDomain.GetITypeByCQValue(parent); parenttype._class.IndexSet(content, obj, key.GetObject(), left.GetObject()); CQ_Expression_GetValue g = f._expressions[0] as CQ_Expression_GetValue; content.Set(g.value_name, parent); } #if CQUARK_DEBUG content.OutStack(this); #endif return(CQ_Value.Null); }