Пример #1
0
        private void ReadConstants()
        {
            int Count = Stream.ReadInt32();
            List <LuaConstant> Consts = new List <LuaConstant>(Count);

            for (int Idx = 0; Idx < Count; Idx++)
            {
                LuaConstantType Type  = (LuaConstantType)Stream.ReadByte();
                LuaConstant     Const = LuaNil;

                if (Type == LuaConstantType.BOOL)
                {
                    Const = Stream.ReadBoolean();
                }
                else if (Type == LuaConstantType.NUMBER)
                {
                    Const = Stream.ReadDouble();
                }
                else if (Type == LuaConstantType.STRING)
                {
                    Const = Stream.ReadCString();
                }

                Consts.Add(Const);
            }

            Proto.Consts = Consts;
        }
Пример #2
0
        private void DumpConstants(List <LuaConstant> Constants)
        {
            DumpInt(Constants.Count);

            for (int Idx = 0; Idx < Constants.Count; Idx++)
            {
                LuaConstant Const = Constants[Idx];

                DumpByte((byte)Const.Type);

                switch (Const.Type)
                {
                case LuaConstantType.BOOL:
                    DumpBytes(BitConverter.GetBytes(Const.Boolean));

                    break;

                case LuaConstantType.NUMBER:
                    DumpBytes(BitConverter.GetBytes(Const.Number));

                    break;

                case LuaConstantType.STRING:
                    DumpString(Const.String);

                    break;
                }
            }
        }
Пример #3
0
        List <LuaConstant> LoadConstants(ref FuncNode curNode)
        {
            int constNum = undumper.LoadInt();

            List <LuaConstant> luaConstants = new List <LuaConstant>();

            for (int i = 0; i < constNum; ++i)
            {
                byte type = undumper.LoadByte();

                LuaConstant curConst;

                switch ((ConstantType)type)
                {
                case ConstantType.LUA_TNIL:
                    curConst = new LuaConstant();
                    break;

                case ConstantType.LUA_TBOOLEAN:
                    curConst = new LuaBoolean();
                    break;

                case ConstantType.LUA_TNUMBER:
                    curConst = new LuaNumber();
                    break;

                case ConstantType.LUA_TSTRING:
                    curConst = new LuaString();
                    break;

                default:
                    curConst = new LuaConstant();
                    break;
                }

                curConst.Type = (ConstantType)type;

                switch (curConst.Type)
                {
                case ConstantType.LUA_TNIL:
                    // DO NOTHING
                    break;

                case ConstantType.LUA_TBOOLEAN:
                    curConst.Data    = new byte[1];
                    curConst.Data[0] = undumper.LoadByte();
                    break;

                case ConstantType.LUA_TNUMBER:
                    curConst.Data = undumper.LoadBlock(sizeof(double));
                    break;

                case ConstantType.LUA_TSTRING:
                    curConst.Data = Encoding.ASCII.GetBytes(undumper.LoadString());
                    break;

                default:
                    break;
                }

                luaConstants.Add(curConst);
            }

            int funcNum = undumper.LoadInt();

            for (int i = 0; i < funcNum; ++i)
            {
                LoadFunction(ref curNode);
            }

            return(luaConstants);
        }