示例#1
0
        public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc)
        {
            Delegate _dele = delefunc.cacheFunction(null);

            if (_dele != null)
            {
                return(_dele);
            }

            var func = delefunc.calltype.functions[delefunc.function];
            Action <T, T1, T2> dele;

            if (func.expr_runtime != null)
            {
                dele = (T param0, T1 param1, T2 param2) =>
                {
                    CLS_Content content = CLS_Content.NewContent(env);
#if UNITY_EDITOR
                    try{
#endif
                    content.CallThis = delefunc.callthis;
                    content.CallType = delefunc.calltype;
                    content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0);
                    content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1);
                    content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2);
                    func.expr_runtime.ComputeValue(content);
                    CLS_Content.PoolContent(content);
#if UNITY_EDITOR
                }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                };
            }
            else
            {
                dele = (T param0, T1 param1, T2 param2) => { };
            }

            if (this.sysType != typeof(Action <T, T1, T2>))
            {
                _dele = Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method);
            }
            else
            {
                _dele = dele;
            }
            return(delefunc.cacheFunction(_dele));
        }
        public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc)
        {
            Delegate _dele = delefunc.cacheFunction(null);

            if (_dele != null)
            {
                return(_dele);
            }

            var             func = delefunc.calltype.functions[delefunc.function];
            NonVoidDelegate dele;

            if (func.expr_runtime != null)
            {
                dele = delegate(T param, T1 param1)
                {
                    CLS_Content content = CLS_Content.NewContent(env);
#if UNITY_EDITOR
                    try{
#endif
                    content.CallThis = delefunc.callthis;
                    content.CallType = delefunc.calltype;
                    content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param);
                    content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1);
                    CLS_Content.Value retValue = func.expr_runtime.ComputeValue(content);
                    CLS_Content.PoolContent(content);
                    return((ReturnType)retValue.value);

#if UNITY_EDITOR
                }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); return(default(ReturnType)); }
#endif
                };
            }
            else
            {
                dele = delegate(T param, T1 param1) { return(default(ReturnType)); };
            }

            _dele = Delegate.CreateDelegate(this.type, dele.Target, dele.Method);
            return(delefunc.cacheFunction(_dele));
        }
示例#3
0
        public CLS_Content.Value MemberCall(CLS_Content contentParent, object object_this, string func, BetterList <CLS_Content.Value> _params, bool isBaseCall = false)
        {
            SInstance callThis = object_this as SInstance;

            // 成员函数判断
            Function fun;

            if (this.functions.TryGetValue(func, out fun))
            {
#if UNITY_EDITOR
                if (fun.bStatic)
                {
                    throw new Exception("不能通过实例来调用静态函数: " + this.Name + "." + func);
                }
#endif
                CLS_Content.Value value = null;

                SType callType = this;

                if (isBaseCall)
                {
                    SType          tempType = contentParent.CallType.BaseType;
                    SType.Function tempFun;
                    while (tempType != null)
                    {
                        if (tempType.functions.TryGetValue(func, out tempFun))
                        {
                            if (tempFun.ownerType == null || tempFun.ownerType == tempType)
                            {
                                callType = tempType;
                                fun      = tempFun;
                                break;
                            }
                        }
                        tempType = tempType.BaseType;
                    }
                }
                else
                {
                    if (callType != callThis.type)
                    {
                        SType    tempType = callThis.type;
                        Function tempFun;
                        while (tempType != null)
                        {
                            if (tempType.functions.TryGetValue(func, out tempFun))
                            {
                                if (tempFun.ownerType == null || tempFun.ownerType == tempType)
                                {
                                    callType = tempType;
                                    fun      = tempFun;
                                    break;
                                }
                            }
                            tempType = tempType.BaseType;
                        }
                    }
                    else if (fun.ownerType != null && fun.ownerType != callType)
                    {
                        callType = fun.ownerType;
                    }
                }

                if (fun.expr_runtime != null)
                {
                    CLS_Content content = CLS_Content.NewContent(contentParent.environment);
#if UNITY_EDITOR
                    contentParent.InStackContent(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    content.CallType = callType;
                    content.CallThis = callThis;

                    for (int i = 0, count = fun._paramtypes.Count; i < count; i++)
                    {
                        content.DefineAndSet(fun._paramnames[i], fun._paramtypes[i].type, _params[i].value);
                    }

                    value = fun.expr_runtime.ComputeValue(content);
                    if (value != null)
                    {
                        value.breakBlock = 0;
                    }
#if UNITY_EDITOR
                    contentParent.OutStackContent(content);
#endif
                    CLS_Content.PoolContent(content);
                }

                return(value);
            }

            // 委托判断
            CLS_Content.Value mDeleVal;
            if (callThis.member.TryGetValue(func, out mDeleVal))
            {
                Delegate dele = mDeleVal.value as Delegate;
                if (dele != null)
                {
                    CLS_Content.Value value = new CLS_Content.Value();
                    value.type = null;
                    object[] objs = CLS_Content.ParamObjsArray[_params.size];
                    for (int i = 0; i < _params.size; i++)
                    {
                        objs[i] = _params[i].value;
                    }
                    value.value = dele.DynamicInvoke(objs);
                    if (value.value != null)
                    {
                        value.type = value.value.GetType();
                    }
                    value.breakBlock = 0;
                    return(value);
                }
            }
            throw new NotImplementedException("未实现成员函数: " + this.Name + "." + func);
        }
        IEnumerator CustomCoroutine(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CLS_Content.Value retVal = null;
            ICLS_Expression   exp    = null;

            for (int i = 0, count = listParam.Count; i < count; i++)
            {
                exp = listParam[i];
                CLS_Expression_LoopFor expLoopFor = exp as CLS_Expression_LoopFor;
                if (expLoopFor != null)
                {
                    content.InStack(expLoopFor);
                    content.DepthAdd();

                    ICLS_Expression expr_init     = expLoopFor.listParam[0];
                    ICLS_Expression expr_continue = expLoopFor.listParam[1];
                    ICLS_Expression expr_step     = expLoopFor.listParam[2];
                    ICLS_Expression expr_block    = expLoopFor.listParam[3];

#if UNITY_EDITOR
                    try
                    {
#endif
                    if (expr_init != null)
                    {
                        expr_init.ComputeValue(content);
                    }
#if UNITY_EDITOR
                }
                catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                    for (;;)
                    {
#if UNITY_EDITOR
                        try
                        {
#endif
                        if (expr_continue != null && !(bool)expr_continue.ComputeValue(content).value)
                        {
                            break;
                        }
#if UNITY_EDITOR
                    }
                    catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                        if (expr_block != null)
                        {
                            if (expr_block is CLS_Expression_Block)
                            {
                                content.InStack(expr_block);
                                content.DepthAdd();
                                for (int j = 0, count2 = expr_block.listParam.Count; j < count2; j++)
                                {
#if UNITY_EDITOR
                                    try
                                    {
#endif
                                    retVal = expr_block.listParam[j].ComputeValue(content);
#if UNITY_EDITOR
                                }
                                catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                                    if (retVal != null)
                                    {
                                        if (retVal.breakBlock == 12)
                                        {
                                            CLS_Content.PoolContent(content);
                                            yield break;
                                        }
                                        else if (retVal.breakBlock == 13)
                                        {
                                            yield return(retVal.value);
                                        }
                                        else if (retVal.breakBlock > 1)
                                        {
                                            break;
                                        }
                                    }
                                }
                                content.DepthRemove();
                                content.OutStack(expr_block);
                            }
                            else
                            {
#if UNITY_EDITOR
                                try
                                {
#endif
                                retVal = expr_block.ComputeValue(content);
#if UNITY_EDITOR
                            }
                            catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                                if (retVal != null)
                                {
                                    if (retVal.breakBlock == 12)
                                    {
                                        CLS_Content.PoolContent(content);
                                        yield break;
                                    }
                                    else if (retVal.breakBlock == 13)
                                    {
                                        yield return(retVal.value);
                                    }
                                    else if (retVal.breakBlock > 1)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
#if UNITY_EDITOR
                        try
                        {
#endif
                        if (expr_step != null)
                        {
                            expr_step.ComputeValue(content);
                        }
#if UNITY_EDITOR
                    }
                    catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                    }

                    content.DepthRemove();
                    content.OutStack(expLoopFor);
                }
                else
                {
#if UNITY_EDITOR
                    try
                    {
#endif
                    retVal = exp.ComputeValue(content);
#if UNITY_EDITOR
                }
                catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                    if (retVal != null)
                    {
                        if (retVal.breakBlock == 12)
                        {
                            CLS_Content.PoolContent(content);
                            yield break;
                        }
                        else if (retVal.breakBlock == 13)
                        {
                            yield return(retVal.value);
                        }
                    }
                }
            }
            CLS_Content.PoolContent(content);
        }
示例#5
0
        public CLS_Content.Value StaticCall(CLS_Content contentParent, string func, BetterList <CLS_Content.Value> _params)
        {
            if (staticMemberContent == null)
            {
                NewStatic(contentParent.environment);
            }

            // 静态函数判断
            Function fun;

            if (this.functions.TryGetValue(func, out fun))
            {
#if UNITY_EDITOR
                if (!fun.bStatic)
                {
                    throw new Exception("成员函数必须通过实例来调用: " + this.Name + "." + func);
                }
#endif
                CLS_Content.Value value = null;
                if (fun.expr_runtime != null)
                {
                    CLS_Content content = CLS_Content.NewContent(contentParent.environment);
#if UNITY_EDITOR
                    contentParent.InStackContent(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    content.CallType = this;
                    content.CallThis = null;

                    for (int i = 0, count = fun._paramtypes.Count; i < count; i++)
                    {
                        content.DefineAndSet(fun._paramnames[i], fun._paramtypes[i].type, _params[i].value);
                    }

                    value = fun.expr_runtime.ComputeValue(content);
                    if (value != null)
                    {
                        value.breakBlock = 0;
                    }
#if UNITY_EDITOR
                    contentParent.OutStackContent(content);
#endif
                    CLS_Content.PoolContent(content);
                }
                return(value);
            }

            // 委托判断
            CLS_Content.Value smDeleVal;
            if (this.staticMemberValues.TryGetValue(func, out smDeleVal))
            {
                Delegate dele = smDeleVal.value as Delegate;
                if (dele != null)
                {
                    CLS_Content.Value value = new CLS_Content.Value();
                    value.type = null;
                    object[] objs = CLS_Content.ParamObjsArray[_params.size];
                    for (int i = 0; i < _params.size; i++)
                    {
                        objs[i] = _params[i].value;
                    }
                    value.value = dele.DynamicInvoke(objs);
                    if (value.value != null)
                    {
                        value.type = value.value.GetType();
                    }
                    value.breakBlock = 0;
                    return(value);
                }
            }

            throw new NotImplementedException("未实现静态函数: " + this.Name + "." + func);
        }