Пример #1
0
        internal void ClearTable()
        {
            Contract.Assert(Type == ValueType.TABLE);

            TablePart table = Value.RefPartHandle.ConverToTablePart();

            table.Clear();
        }
Пример #2
0
        /// <summary>
        ///    获取字段,没有的话就产生一个nil
        /// </summary>
        /// <param name="filed"></param>
        /// <returns></returns>
        public ScriptObject GetOrCreateFileld(string filed)
        {
            Contract.Assert(Type == ValueType.TABLE);

            TablePart table = Value.RefPartHandle.ConverToTablePart();

            ScriptObject s = table.TryGetValue(filed);

            if (s == null)
            {
                s = ScriptObject.CreateNil();
                table.AddFileld(filed, s);
            }
            return(s);
        }
Пример #3
0
        internal ScriptObject GetOrCreateFileld(ScriptObject index)
        {
            Contract.Assert(Type == ValueType.TABLE);

            TablePart table = Value.RefPartHandle.ConverToTablePart();

            ScriptObject s = null;

            switch (index.Type)
            {
            case ValueType.NUMBER:

                int at = (int)index.Value.Number;

                s = Value.RefPartHandle.ConverToTablePart().IndexAt(at);

                if (s == null)
                {
                    s = ScriptObject.CreateNil();
                }
                table.AddFileld(at, s);
                break;

            case ValueType.STRING:

                string key = index.Value.RefPartHandle.ConverToStringPart().Value;

                s = table.TryGetValue(key);
                if (s == null)
                {
                    s = ScriptObject.CreateNil();
                }
                table.AddFileld(key, s);

                break;

            default:
                Contract.Assert(false);
                break;
            }
            return(s);
        }
Пример #4
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);
        }