예제 #1
0
        public void Evaluate(StoryInstance instance, object iterator, object[] args)
        {
            StackElementInfo stackInfo = NewStackElementInfo();

            //调用实参部分需要在栈建立之前运算,结果需要记录在栈上
            for (int i = 0; i < m_LoadedArgs.Count; ++i)
            {
                stackInfo.m_Args.Add(m_LoadedArgs[i].Clone());
            }
            for (int i = 0; i < stackInfo.m_Args.Count; i++)
            {
                stackInfo.m_Args[i].Evaluate(instance, iterator, args);
            }
            //实参处理完,进入函数体执行,创建新的栈
            PushStack(instance, stackInfo);
            try {
                for (int i = 0; i < m_ArgNames.Count && i < stackInfo.m_Args.Count; ++i)
                {
                    instance.SetVariable(m_ArgNames[i], stackInfo.m_Args[i].Value);
                }
                Prepare(stackInfo);
                stackInfo.m_HaveValue = true;
                for (int i = 0; i < stackInfo.m_Commands.Count; ++i)
                {
                    //函数调用命令需要忽略其中的wait指令(从而不会出现“挂起-恢复”行为),所以这里传的delta值是一个很大的值,目的是为了让wait直接结束
                    stackInfo.m_Commands[i].Execute(instance, StoryValueHelper.c_MaxWaitCommandTime, iterator, args);
                }
                instance.TryGetVariable(m_ReturnName, out stackInfo.m_Value);
            } finally {
                PopStack(instance);
            }
        }
예제 #2
0
        public void Evaluate(StoryInstance instance, StoryMessageHandler handler, BoxedValue iterator, BoxedValueList args)
        {
            var stackInfo = StoryLocalInfo.New();
            var runtime   = StoryRuntime.New();

            //调用实参部分需要在栈建立之前运算,结果需要记录在栈上
            for (int i = 0; i < m_LoadedArgs.Count; ++i)
            {
                stackInfo.Args.Add(m_LoadedArgs[i].Clone());
            }
            foreach (var pair in m_LoadedOptArgs)
            {
                stackInfo.OptArgs.Add(pair.Key, pair.Value.Clone());
            }
            runtime.Arguments          = instance.NewBoxedValueList();
            runtime.Arguments.Capacity = stackInfo.Args.Count;
            for (int i = 0; i < stackInfo.Args.Count; i++)
            {
                stackInfo.Args[i].Evaluate(instance, handler, iterator, args);
                runtime.Arguments.Add(stackInfo.Args[i].Value);
            }
            runtime.Iterator = stackInfo.Args.Count;
            foreach (var pair in stackInfo.OptArgs)
            {
                pair.Value.Evaluate(instance, handler, iterator, args);
            }
            //实参处理完,进入函数体执行,创建新的栈
            PushStack(instance, handler, stackInfo, runtime);
            try {
                for (int i = 0; i < m_ArgNames.Count; ++i)
                {
                    if (i < stackInfo.Args.Count)
                    {
                        instance.SetVariable(m_ArgNames[i], stackInfo.Args[i].Value);
                    }
                    else
                    {
                        instance.SetVariable(m_ArgNames[i], BoxedValue.NullObject);
                    }
                }
                foreach (var pair in stackInfo.OptArgs)
                {
                    instance.SetVariable(pair.Key, pair.Value.Value);
                }
                Prepare(runtime);
                stackInfo.HaveValue = true;
                runtime.Tick(instance, handler, long.MaxValue);
                BoxedValue val;
                instance.TryGetVariable(m_ReturnName, out val);
                stackInfo.Value = val;
            } finally {
                instance.RecycleBoxedValueList(runtime.Arguments);
                PopStack(instance, handler);
            }
        }