예제 #1
0
        private static ScriptTable Read(MessageReader reader, string tableName)
        {
            ScriptTable table  = m_Script.CreateTable();
            ScriptArray layout = (ScriptArray)m_Script.GetValue(tableName);
            int         sign   = reader.ReadInt32();

            for (int i = 0; i < layout.Count(); ++i)
            {
                ScriptObject config = layout.GetValue(i);
                if (MessageUtil.HasSign(sign, MessageUtil.ToInt32(config.GetValue(Index).ObjectValue)))
                {
                    string name  = (string)config.GetValue(Name).ObjectValue;
                    string type  = (string)config.GetValue(Type).ObjectValue;
                    bool   array = (bool)config.GetValue(Array).ObjectValue;
                    if (array)
                    {
                        int         count = reader.ReadInt32();
                        ScriptArray arr   = m_Script.CreateArray();
                        for (int j = 0; j < count; ++j)
                        {
                            arr.Add(ReadObject(reader, type));
                        }
                        table.SetValue(name, arr);
                    }
                    else
                    {
                        table.SetValue(name, ReadObject(reader, type));
                    }
                }
            }
            return(table);
        }
예제 #2
0
            public object Call(ScriptObject[] args)
            {
                ScriptNumber num = args[0] as ScriptNumber;

                if (num != null)
                {
                    return(new string(new char[] { Convert.ToChar(num.ToInt32()) }));
                }
                else
                {
                    ScriptArray array = args[0] as ScriptArray;
                    char[]      chars = new char[array.Count()];
                    for (int i = 0; i < array.Count(); ++i)
                    {
                        chars[i] = Convert.ToChar((array.GetValue(i) as ScriptNumber).ToInt32());
                    }
                    return(new string(chars));
                }
            }
예제 #3
0
 private void WriteCustom(TableWriter writer, ScriptArray list, List <PackageField> fields, bool array)
 {
     if (array)
     {
         if (Util.IsEmptyValue(list))
         {
             writer.WriteInt32(0);
         }
         else
         {
             int count = list.Count();
             writer.WriteInt32(count);
             for (int i = 0; i < count; ++i)
             {
                 WriteCustom(writer, list.GetValue(i) as ScriptArray, fields, false);
             }
         }
     }
     else
     {
         if (Util.IsEmptyValue(list))
         {
             for (int i = 0; i < fields.Count; ++i)
             {
                 WriteField(writer, "", fields[i]);
             }
         }
         else
         {
             int count = list.Count();
             if (count != fields.Count)
             {
                 throw new Exception(string.Format("填写字段数量与数据机构字段数量不一致 需要数量 {0}  填写数量{1}", fields.Count, count));
             }
             for (int i = 0; i < count; ++i)
             {
                 WriteField(writer, list.GetValue(i), fields[i]);
             }
         }
     }
 }
예제 #4
0
            public object Call(ScriptObject[] args)
            {
                string      separator = (args[0] as ScriptString).Value;
                ScriptArray value     = (args[1] as ScriptArray);
                var         count     = value.Count();

                string[] values = new string[count];
                for (int i = 0; i < count; ++i)
                {
                    values[i] = value.GetValue(i).ToString();
                }
                return(string.Join(separator, values));
            }
예제 #5
0
        private static void Write(Script script, ScorpioWriter writer, ScriptTable table, string tableName)
        {
            ScriptArray layout = (ScriptArray)script.GetValue(tableName);
            int         sign   = 0;

            for (int i = 0; i < layout.Count(); ++i)
            {
                ScriptObject config = layout.GetValue(i);
                if (table != null && table.HasValue(config.GetValue(Name).ObjectValue))
                {
                    sign = ScorpioUtil.AddSign(sign, ScorpioUtil.ToInt32(config.GetValue(Index).ObjectValue));
                }
            }
            writer.WriteInt32(sign);
            for (int i = 0; i < layout.Count(); ++i)
            {
                ScriptObject config = layout.GetValue(i);
                string       name   = (string)config.GetValue(Name).ObjectValue;
                if (table != null && table.HasValue(name))
                {
                    string type  = (string)config.GetValue(Type).ObjectValue;
                    bool   array = (bool)config.GetValue(Array).ObjectValue;
                    if (array)
                    {
                        ScriptArray arr = table.GetValue(name) as ScriptArray;
                        writer.WriteInt32(arr.Count());
                        for (int j = 0; j < arr.Count(); ++j)
                        {
                            WriteObject(script, writer, type, arr.GetValue(j));
                        }
                    }
                    else
                    {
                        WriteObject(script, writer, type, table.GetValue(name));
                    }
                }
            }
        }
예제 #6
0
    public void Initialize(Script script, ScriptTable table)
    {
        Table = table;
        table.SetValue("com", script.CreateUserdata(this));
        ScriptArray functions = table.GetValue("registerFunction") as ScriptArray;

        if (functions != null)
        {
            for (int i = 0; i < functions.Count(); ++i)
            {
                registerFunctions.Add((string)(functions.GetValue(i).ObjectValue));
            }
        }
        OnStart();
    }
예제 #7
0
        public static ScriptTable Read(Script script, ScorpioReader reader, string tableName, bool hasSign)
        {
            ScriptTable table     = script.CreateTable();
            ScriptArray layout    = (ScriptArray)script.GetValue(tableName);
            bool        isInvalid = true;
            int         sign      = hasSign ? reader.ReadInt32() : 0;

            for (int i = 0; i < layout.Count(); ++i)
            {
                ScriptObject config = layout.GetValue(i);
                if (!hasSign || ScorpioUtil.HasSign(sign, ScorpioUtil.ToInt32(config.GetValue(Index).ObjectValue)))
                {
                    string  name    = (string)config.GetValue(Name).ObjectValue;
                    string  type    = (string)config.GetValue(Type).ObjectValue;
                    bool    array   = (bool)config.GetValue(Array).ObjectValue;
                    Invalid invalid = new Invalid();
                    if (array)
                    {
                        int         count = reader.ReadInt32();
                        ScriptArray value = script.CreateArray();
                        for (int j = 0; j < count; ++j)
                        {
                            value.Add(ReadObject(script, reader, type, hasSign, invalid));
                        }
                        table.SetValue(name, value);
                        if (count > 0)
                        {
                            isInvalid = false;
                        }
                    }
                    else
                    {
                        table.SetValue(name, ReadObject(script, reader, type, hasSign, invalid));
                        if (!invalid.value)
                        {
                            isInvalid = false;
                        }
                    }
                }
            }
            table.SetValue("IsInvalid", script.CreateBool(isInvalid));
            return(table);
        }
예제 #8
0
 //是否是非法值
 public static bool IsEmptyValue(ScriptArray value)
 {
     return(value == null || value.Count() == 0);
 }
예제 #9
0
        /// <summary>
        /// 读取一个网络协议或者一行table数据
        /// </summary>
        /// <param name="script">脚本引擎对象</param>
        /// <param name="reader">读取类</param>
        /// <param name="tableManager">tableManager类</param>
        /// <param name="fileName">table用文件名字</param>
        /// <param name="layoutTableName">结构名字</param>
        /// <param name="message">是否是网络协议</param>
        private static ScriptTable Read(Script script, ScorpioReader reader, ScriptTable tableManager, string fileName, string layoutTableName, bool message)
        {
            ScriptTable table     = script.CreateTable();
            ScriptArray layout    = (ScriptArray)script.GetValue(layoutTableName);
            int         sign      = message ? reader.ReadInt32() : 0;
            bool        isInvalid = true;
            string      id        = null;

            for (int i = 0; i < layout.Count(); ++i)
            {
                ScriptObject config = layout.GetValue(i);
                if (message && !ScorpioUtil.HasSign(sign, ScorpioUtil.ToInt32(config.GetValue(Index).ObjectValue)))
                {
                    continue;
                }
                string  name    = config.GetValue(Name).ToString();         //字段名字
                string  type    = config.GetValue(Type).ToString();         //字段类型
                bool    array   = config.GetValue(Array).LogicOperation();  //是否是数组
                Invalid invalid = new Invalid();                            //本行是否是无效行
                if (array)
                {
                    int         count = reader.ReadInt32();     //读取元素个数
                    ScriptArray value = script.CreateArray();
                    for (int j = 0; j < count; ++j)
                    {
                        value.Add(ReadObject(script, reader, tableManager, fileName, type, message, invalid));
                    }
                    table.SetValue(name, value);
                    if (count > 0)
                    {
                        isInvalid = false;
                    }
                }
                else
                {
                    if (message)
                    {
                        table.SetValue(name, ReadObject(script, reader, tableManager, fileName, type, message, invalid));
                    }
                    else
                    {
                        ScriptTable attribute = config.GetValue(Attribute) as ScriptTable;
                        if (attribute.Count() == 0)
                        {
                            var obj = ReadObject(script, reader, tableManager, fileName, type, message, invalid);
                            table.SetValue(name, obj);
                            if (!invalid.value)
                            {
                                isInvalid = false;
                            }
                            if (string.IsNullOrEmpty(id))
                            {
                                id = ScorpioUtil.ToInt32(obj.ObjectValue).ToString();
                            }
                        }
                        else
                        {
                            ReadObject(script, reader, tableManager, fileName, type, message, invalid);     //先读取一个值  如果是多国语言 生成数据的时候会写入一个空字符串
                            table.SetValue(name, script.CreateObject(tableManager.GetValue("getValue").call(attribute, fileName, name, id)));
                        }
                    }
                }
            }
            if (!message)
            {
                table.SetValue("IsInvalid", script.CreateBool(isInvalid));
            }
            return(table);
        }