示例#1
0
        public object ConvertTo(CQ_Content env, object src, CQType targetType)
        {
            ICQ_Type_Dele dele = env.environment.GetType(targetType) as ICQ_Type_Dele;

            return(dele.CreateDelegate(env.environment, src as DeleLambda));
            //throw new NotImplementedException();
        }
示例#2
0
        public override object ConvertTo(CQ_Content env, object src, CQType targetType)
        {
            bool   convertSuccess  = false;
            object convertedObject = NumericTypeUtils.TryConvertTo <ulong>(src, targetType, out convertSuccess);

            if (convertSuccess)
            {
                return(convertedObject);
            }

            return(base.ConvertTo(env, src, targetType));
        }
示例#3
0
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
            content.InStack(this);
            {
                if (listParam[0].hasCoroutine)
                {
                    yield return(coroutine.StartNewCoroutine(listParam[0].CoroutineCompute(content, coroutine)));
                }
                else
                {
                    CQ_Content.Value v = listParam[0].ComputeValue(content);

                    {
                        object val        = v.value;
                        CQType value_type = null;
                        if (content.values.ContainsKey(value_name))
                        {
                            value_type = content.values[value_name].type;
                        }
                        else
                        {
                            if (content.CallType != null)
                            {
                                if (content.CallType.members.ContainsKey(value_name))
                                {
                                    if (content.CallType.members[value_name].bStatic)
                                    {
                                        value_type = content.CallType.staticMemberInstance[value_name].type;
                                    }
                                    else
                                    {
                                        value_type = content.CallThis.member[value_name].type;
                                    }
                                }
                            }
                        }
                        //val = v.value;
                        if ((Type)value_type != typeof(CQ_Type_Var.var) && value_type != v.type)
                        {
                            val = content.environment.GetType(v.type).ConvertTo(content, v.value, value_type);
                        }


                        content.Set(value_name, val);
                    }
                }
            }
            content.OutStack(this);
        }
示例#4
0
        /// <summary>
        /// 类型转换.
        /// </summary>
        /// <typeparam name="OriginalType"></typeparam>
        /// <param name="src"></param>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static object TryConvertTo <OriginalType>(object src, CQType targetType, out bool convertSuccess) where OriginalType : struct
        {
            convertSuccess = true;

            try
            {
                decimal srcValue = GetDecimalValue(typeof(OriginalType), src);
                return(Decimal2TargetType(targetType, srcValue));
            }
            catch (Exception)
            {
                convertSuccess = false;
                return(null);
            }
        }
示例#5
0
        public object ConvertTo(CQ_Content env, object src, CQType targetType)
        {
            var type = env.environment.GetType(targetType);

            if (this.type == type || (Type)targetType == typeof(object))
            {
                return(src);
            }
            if (this.types.Contains(type))
            {
                return(src);
            }

            throw new NotImplementedException();
        }
示例#6
0
        public void Define(string name, CQType type)
        {
            if (values.ContainsKey(name))
            {
                throw new Exception("已经定义过");
            }
            Value v = new Value();

            v.type       = type;
            values[name] = v;
            if (tvalues.Count > 0)
            {
                tvalues.Peek().Add(name);//暂存临时变量
            }
        }
示例#7
0
        public void DefineAndSet(string name, CQType type, object value)
        {
            if (values.ContainsKey(name))
            {
                throw new Exception(type.ToString() + ":" + name + "已经定义过");
            }
            Value v = new Value();

            v.type       = type;
            v.value      = value;
            values[name] = v;
            if (tvalues.Count > 0)
            {
                tvalues.Peek().Add(name);//暂存临时变量
            }
        }
示例#8
0
        public ICQ_Type GetType(CQType type)
        {
            if (type == null)
            {
                return(typess["null"]);
            }

            ICQ_Type ret = null;

            if (types.TryGetValue(type, out ret) == false)
            {
                logger.Log_Warn("(CQcript)类型未注册,将自动注册一份匿名:" + type.ToString());
                ret = RegHelper_Type.MakeType(type, "");
                RegType(ret);
            }
            return(ret);
        }
示例#9
0
 public object ConvertTo(CQ_Content env, object src, CQType targetType)
 {
     if ((Type)targetType == typeof(string))
     {
         return(src);
     }
     if ((Type)targetType == typeof(void))
     {
         return(null);
     }
     if (((Type)targetType).IsAssignableFrom(typeof(string)))
     //if((Type)targetType== typeof(object))
     {
         return(src);
     }
     return(null);
 }
示例#10
0
 public object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
 {
     throw new NotImplementedException();
 }
示例#11
0
 public object ConvertTo(CQ_Content env, object src, CQType targetType)
 {
     throw new NotImplementedException();
 }
示例#12
0
 public object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
 {
     returntype = typeof(string);
     if (code == '+')
     {
         if (right.value == null)
         {
             return((string)left + "null");
         }
         else
         {
             return((string)left + right.value.ToString());
         }
     }
     throw new NotImplementedException();
 }
示例#13
0
        public virtual object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
        {
            returntype = type;
            System.Reflection.MethodInfo call = null;
            //var m = ((Type)type).GetMembers();
            if (code == '+')
            {
                if ((Type)right.type == typeof(string))
                {
                    returntype = typeof(string);
                    return(left.ToString() + right.value as string);
                }
                call = _type.GetMethod("op_Addition", new Type[] { this.type, right.type });
            }
            else if (code == '-')//base = {CQcriptExt.Vector3 op_Subtraction(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Subtraction", new Type[] { this.type, right.type });
            }
            else if (code == '*')//[2] = {CQcriptExt.Vector3 op_Multiply(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Multiply", new Type[] { this.type, right.type });
            }
            else if (code == '/')//[3] = {CQcriptExt.Vector3 op_Division(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Division", new Type[] { this.type, right.type });
            }
            else if (code == '%')//[4] = {CQcriptExt.Vector3 op_Modulus(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Modulus", new Type[] { this.type, right.type });
            }

            var obj = call.Invoke(null, new object[] { left, right.value });

            //function.StaticCall(env,"op_Addtion",new List<ICL>{})
            return(obj);
        }
示例#14
0
        public virtual object ConvertTo(CQ_Content env, object src, CQType targetType)
        {
            Type targettype = (Type)targetType;

            if (this._type == targettype)
            {
                return(src);
            }

            //type.get

            if (_type.IsEnum)
            {
                if ((Type)targetType == typeof(int))
                {
                    return(System.Convert.ToInt32(src));
                }
                else if ((Type)targetType == typeof(uint))
                {
                    return(System.Convert.ToUInt32(src));
                }
                else if ((Type)targetType == typeof(short))
                {
                    return(System.Convert.ToInt16(src));
                }
                else if ((Type)targetType == typeof(ushort))
                {
                    return(System.Convert.ToUInt16(src));
                }
                else
                {
                    return(System.Convert.ToInt32(src));
                }
            }
            else if (targettype != null && targettype.IsEnum)
            {
                return(Enum.ToObject(targettype, src));
            }
            var ms = _type.GetMethods();

            foreach (var m in ms)
            {
                if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == targettype)
                {
                    return(m.Invoke(null, new object[] { src }));
                }
            }
            if (targettype != null)
            {
                if (targettype.IsAssignableFrom(_type))
                {
                    return(src);
                }
                if (src != null && targettype.IsInstanceOfType(src))
                {
                    return(src);
                }
            }
            else
            {
                return(src);
            }

            return(null);
        }
示例#15
0
        /// <summary>
        /// Math2Value.
        /// </summary>
        /// <typeparam name="LeftType"></typeparam>
        /// <param name="opCode"></param>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="returntype"></param>
        /// <param name="math2ValueSuccess"></param>
        /// <returns></returns>
        public static object Math2Value <LeftType>(char opCode, object left, CQ_Content.Value right, out CQType returntype, out bool math2ValueSuccess) where LeftType : struct
        {
            math2ValueSuccess = true;

            try
            {
                decimal leftValue  = GetDecimalValue(typeof(LeftType), left);
                decimal rightValue = GetDecimalValue(right.type, right.value);
                decimal finalValue = 0;

                switch (opCode)
                {
                case '+':
                    finalValue = leftValue + rightValue;
                    break;

                case '-':
                    finalValue = leftValue - rightValue;
                    break;

                case '*':
                    finalValue = leftValue * rightValue;
                    break;

                case '/':
                    finalValue = leftValue / rightValue;
                    break;

                case '%':
                    finalValue = leftValue % rightValue;
                    break;

                default:
                    throw new Exception("Invalid math operation::opCode = " + opCode);
                }

                returntype = GetReturnType_Math2Value(typeof(LeftType), right.type);
                return(Decimal2TargetType(returntype, finalValue));
            }
            catch (Exception)
            {
                math2ValueSuccess = false;
                returntype        = null;
                return(null);
            }
        }
示例#16
0
        public override object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
        {
            returntype = null;

            if (left is DeleEvent)
            {
                DeleEvent info     = left as DeleEvent;
                Delegate  calldele = null;

                //!--exist bug.

                /*if (right.value is DeleFunction) calldele = CreateDelegate(env.environment, right.value as DeleFunction);
                 * else if (right.value is DeleLambda) calldele = CreateDelegate(env.environment, right.value as DeleLambda);
                 * else if (right.value is Delegate) calldele = right.value as Delegate;*/

                object rightValue = right.value;
                if (rightValue is DeleFunction)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleFunction);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleFunction);
                    }
                }
                else if (rightValue is DeleLambda)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleLambda);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleLambda);
                    }
                }
                else if (rightValue is Delegate)
                {
                    calldele = rightValue as Delegate;
                }

                if (code == '+')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Map(rightValue as IDeleBase, calldele);
                    //}
                    return(info);
                }
                else if (code == '-')
                {
                    info._event.RemoveEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Destroy(rightValue as IDeleBase);
                    //}
                    return(info);
                }
            }
            else if (left is Delegate || left == null)
            {
                Delegate info     = left as Delegate;
                Delegate calldele = null;
                if (right.value is DeleFunction)
                {
                    calldele = CreateDelegate(env.environment, right.value as DeleFunction);
                }
                else if (right.value is DeleLambda)
                {
                    calldele = CreateDelegate(env.environment, right.value as DeleLambda);
                }
                else if (right.value is Delegate)
                {
                    calldele = right.value as Delegate;
                }
                if (code == '+')
                {
                    return(Delegate.Combine(info, calldele));;
                }
                else if (code == '-')
                {
                    return(Delegate.Remove(info, calldele));
                }
            }
            return(new NotSupportedException());
        }
示例#17
0
 public object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
 {
     throw new NotImplementedException("code:" + code + " right:+" + right.type.ToString() + "=" + right.value);
 }
示例#18
0
        //public ICQ_Type_Dele GetDeleTypeBySign(string sign)
        //{
        //    if (deleTypes.ContainsKey(sign) == false)
        //    {
        //        return null;
        //        //logger.Log_Error("(CQcript)类型未注册:" + sign);

        //    }
        //    return deleTypes[sign];

        //}
        public ICQ_Type GetTypeByKeyword(string keyword)
        {
            ICQ_Type ret = null;

            if (string.IsNullOrEmpty(keyword))
            {
                return(null);
            }
            if (typess.TryGetValue(keyword, out ret) == false)
            {
                if (keyword[keyword.Length - 1] == '>')
                {
                    int           iis    = keyword.IndexOf('<');
                    string        func   = keyword.Substring(0, iis);
                    List <string> _types = new List <string>();
                    int           istart = iis + 1;
                    int           inow   = istart;
                    int           dep    = 0;
                    while (inow < keyword.Length)
                    {
                        if (keyword[inow] == '<')
                        {
                            dep++;
                        }
                        if (keyword[inow] == '>')
                        {
                            dep--;
                            if (dep < 0)
                            {
                                _types.Add(keyword.Substring(istart, inow - istart));
                                break;
                            }
                        }

                        if (keyword[inow] == ',' && dep == 0)
                        {
                            _types.Add(keyword.Substring(istart, inow - istart));
                            istart = inow + 1;
                            inow   = istart;
                            continue;;
                        }

                        inow++;
                    }

                    //var funk = keyword.Split(new char[] { '<', '>', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (typess.ContainsKey(func))
                    {
                        Type gentype = GetTypeByKeyword(func).type;
                        if (gentype.IsGenericTypeDefinition)
                        {
                            Type[] types = new Type[_types.Count];
                            for (int i = 0; i < types.Length; i++)
                            {
                                CQType t  = GetTypeByKeyword(_types[i]).type;
                                Type   rt = t;
                                if (rt == null && t != null)
                                {
                                    rt = typeof(object);
                                }
                                types[i] = rt;
                            }
                            Type IType = gentype.MakeGenericType(types);
                            RegType(CQuark.RegHelper_Type.MakeType(IType, keyword));
                            return(GetTypeByKeyword(keyword));
                        }
                    }
                }
                logger.Log_Error("(CQcript)类型未注册:" + keyword);
            }

            return(ret);
        }
示例#19
0
 public object ConvertTo(CQ_Content env, object src, CQType targetType)
 {
     return(null);
 }
示例#20
0
        public override object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
        {
            bool   math2ValueSuccess = false;
            object value             = NumericTypeUtils.Math2Value <ulong>(code, left, right, out returntype, out math2ValueSuccess);

            if (math2ValueSuccess)
            {
                return(value);
            }

            return(base.Math2Value(env, code, left, right, out returntype));
        }
示例#21
0
 public object Math2Value(CQ_Content env, char code, object left, CQ_Content.Value right, out CQType returntype)
 {
     if ((Type)right.type == typeof(string))
     {
         returntype = typeof(String);
         return("null" + right.value);
     }
     throw new NotImplementedException();
 }