Example #1
0
        Object readConstant(BuffReader buf)
        {
            switch (buf.ReadByte())
            {
            case TAG_NIL:
                return(null);

            case TAG_BOOLEAN:
                return(buf.ReadByte() != 0);

            case TAG_INTEGER:
                return(buf.ReadInt64());

            case TAG_NUMBER:
                return(buf.ReadDouble());

            case TAG_SHORT_STR:
                return(buf.ReadLuaString());

            case TAG_LONG_STR:
                return(buf.ReadLuaString());

            default:
            {
            }
                return(null);
            }
        }
Example #2
0
        static void checkHead(BuffReader buf)
        {
            if (!Enumerable.SequenceEqual(LUA_SIGNATURE, buf.ReadBytes(4)))
            {
                Console.WriteLine("!Array.Equals(LUA_SIGNATURE, buf.ReadBytes(4))");
                for (int i = 0; i < 4; i++)
                {
                    Console.WriteLine($"byte {i}: {LUA_SIGNATURE[i]}");
                }
                return;
            }

            if (buf.ReadByte() != LUAC_VERSION)
            {
                Console.WriteLine($"Version {LUAC_VERSION}");
                Console.WriteLine("buf.ReadByte() != LUAC_VERSION");
            }

            if (buf.ReadByte() != LUAC_FORMAT)
            {
                Console.WriteLine("buf.ReadByte() != LUAC_FORMAT");
            }

            if (!Enumerable.SequenceEqual(LUAC_DATA, buf.ReadBytes(6)))
            {
                Console.WriteLine("!Enumerable.SequenceEqual(LUAC_DATA, buf.ReadBytes(6))");
            }

            if (buf.ReadByte() != CINT_SIZE)
            {
                Console.WriteLine("buf.ReadByte() != CINT_SIZE");
            }

            if (buf.ReadByte() != CSZIET_SIZE)
            {
                Console.WriteLine($"CSZIET_SIZE {CSZIET_SIZE}");
                Console.WriteLine("buf.ReadByte() != CSZIET_SIZE");
            }

            if (buf.ReadByte() != INSTRUCTION_SIZE)
            {
                Console.WriteLine("buf.ReadByte() != INSTRUCTION_SIZE");
            }

            if (buf.ReadByte() != LUA_INTEGER_SIZE)
            {
                Console.WriteLine("buf.ReadByte() != LUA_INTEGER_SIZE");
            }

            if (buf.ReadByte() != LUA_NUMBER_SIZE)
            {
                Console.WriteLine("buf.ReadByte() != LUA_NUMBER_SIZE");
            }

            if (buf.ReadInt64() != LUAC_INT)
            {
                Console.WriteLine("buf.ReadInt64() != LUAC_INT");
            }

            if (buf.ReadDouble() != LUAC_NUM)
            {
                Console.WriteLine("buf.ReadDouble() != LUAC_NUM");
            }
        }