예제 #1
0
        /// <summary>
        ///    以名称获取字段,没有就返回nil
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public ScriptObject GetFileld(string filed)
        {
            Contract.Assert(Type == ValueType.TABLE);

            TablePart tablePart = Value.RefPartHandle.ConverToTablePart();

            ScriptObject s = tablePart.TryGetValue(filed);

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

            ScriptObject metaTable = tablePart.MetaTable;

            if (metaTable != null)
            {
                s = metaTable.GetFileld("_index");

                if (s.Type == ValueType.TABLE)
                {
                    return(s.GetFileld(filed));
                }
                else if (s.Type == ValueType.FUNCTION)
                {
                    //多一次拷贝(实际上)
                    //RunEnvironment.Instance.LocalStack.InvokeFunction(s, this, ScriptObject.CreateString(filed));

                    StackState state = RunEnvironment.Instance.LocalStack;

                    state.PushFunction(s);

                    state.Push(this);

                    state.Push(filed);

                    return(state.InvokeFunction());
                }
            }
            return(RunEnvironment.Nil);
        }
예제 #2
0
        public static ScriptObject GetThisValue()
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            return(stack.This);
        }
예제 #3
0
        public static void SetThisValue(ScriptObject own)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            Instructor.AssignVar(stack.This, own);
        }
예제 #4
0
        public static void SetReturn(ScriptObject res)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.SetReturn(res);
        }
예제 #5
0
        /// <summary>
        ///   设置返回值为空
        /// </summary>
        public static void SetReturnVoid()
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.SetReturnVoid();
        }
예제 #6
0
        /// <summary>
        ///   调用栈中的函数
        /// </summary>
        public static ScriptObject InvokeFuncInStack()
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            return(stack.InvokeFunction());
        }
예제 #7
0
        /// <summary>
        ///    函数参数压栈
        /// </summary>
        /// <param name="parameter"></param>
        public static void PushParameter(ScriptObject parameter)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.PushFuncParameter(parameter);
        }
예제 #8
0
        /// <summary>
        ///    函数压栈
        /// </summary>
        /// <param name="func"></param>
        /// <returns>返回栈中的位置下表</returns>
        public static void PushFunction(ScriptObject func)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.PushFunction(func);
        }
예제 #9
0
        /// <summary>
        ///    将局部变量压栈
        /// </summary>
        /// <param name="obj"></param>
        public static void StackPush(ScriptObject obj)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.Push(obj);
        }
예제 #10
0
        public static void StackPop(int count)
        {
            StackState stack = RunEnvironment.Instance.LocalStack;

            stack.Pop(count);
        }