示例#1
0
        public override LuatValue Resolve(LuatScript script)
        {
            LuatValue value = base.Resolve(script);

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

            LuatTable table      = new LuatTable(null);
            int       fieldIndex = 1;

            foreach (Field field in Fields)
            {
                string key;
                if (null == field.Key)
                {
                    key = (fieldIndex++).ToString();
                }
                else if (field.Key is StringExpression)
                {
                    key = (field.Key as StringExpression).String;
                }
                else if (field.Key is NumberExpression)
                {
                    key = (field.Key as NumberExpression).Number.ToString();
                }
                else if (field.Key is Identifier)
                {
                    key = (field.Key as Identifier).Text;
                }
                else
                {
                    continue;
                }

                if (null != table.Index(key, false))
                {
                    field.AddWarning(script, WarningType.DuplicateTableKey, string.Format("Table already contains key '{0}'", key));
                    continue;
                }

                LuatVariable entry = table.AddChild(key, new LuatVariable(table));
                entry.Description = Description;

                if (null != field.Value)
                {
                    entry.AddAssignment(new Parser.AST.Expression.Reference(script, field.Value, this.DisplayText));
                }
            }

            this.ResolvedValues[script] = table;
            return(table);
        }