public LuaLocalVariable(BinaryReader reader, LuaFunction function) { Function = function; Name = Module.ReadString(reader); ProgramCounterStart = Module.ReadInt(reader); ProgramCounterEnd = Module.ReadInt(reader); }
public LuaFunction(BinaryReader reader, LuaModule module) { Module = module; Source = module.ReadString(reader); LineDefined = module.ReadInt(reader); UpValueCount = reader.ReadByte(); ParameterCount = reader.ReadByte(); HasVariableArguments = reader.ReadByte() != 0; MaxStackSize = reader.ReadByte(); var lineInfoCount = module.ReadInt(reader); LineInfo = new Codex<int>(reader.ReadArrayInt32(lineInfoCount)); var localVariableCount = module.ReadInt(reader); LuaLocalVariable[] localVariables = new LuaLocalVariable[localVariableCount]; for (int index = 0; index < localVariableCount; index++) localVariables[index] = new LuaLocalVariable(reader, this); LocalVariables = new Codex<LuaLocalVariable>(localVariables); var upValueCount = module.ReadInt(reader); string[] upValues = new string[upValueCount]; for (int index = 0; index < upValueCount; index++) upValues[index] = module.ReadString(reader); UpValues = new Codex<string>(upValues); var constantCount = module.ReadInt(reader); Codex<object> constants = new Codex<object>(constantCount); Constants = constants; for (int index = 0; index < constantCount; index++) { LuaType type = (LuaType)reader.ReadByte(); switch (type) { case LuaType.Nil: break; case LuaType.Boolean: constants.Add(reader.ReadByte() != 0); break; case LuaType.Number: constants.Add(module.ReadNumber(reader)); break; case LuaType.String: constants.Add(module.ReadString(reader)); break; default: throw new NotSupportedException(); } } var functionCount = module.ReadInt(reader); LuaFunction[] functions = new LuaFunction[functionCount]; for (int index = 0; index < functionCount; index++) functions[index] = new LuaFunction(reader, index, this); Closures = new Codex<LuaFunction>(functions); var codeCount = module.ReadInt(reader); LuaInstruction[] code = new LuaInstruction[codeCount]; for (int index = 0; index < codeCount; index++) code[index] = new LuaInstruction(this, module.ReadInstructionCode(reader)); Instructions = new Codex<LuaInstruction>(code); }
public LuaInstruction(LuaFunction function, uint code) { this.function = function; Code = code; }
public LuaModule(AssetManager manager, BinaryReader reader, string name) : base(manager, name) { using (reader) { reader.RequireMagic(Magic); VersionCode = reader.ReadByte(); Endianness = reader.ReadByte() != 0 ? ByteOrder.LittleEndian : ByteOrder.BigEndian; IntSize = reader.ReadByte(); SizeTSize = reader.ReadByte(); InstructionSize = reader.ReadByte(); InstructionOpSize = reader.ReadByte(); InstructionASize = reader.ReadByte(); InstructionBSize = reader.ReadByte(); InstructionCSize = reader.ReadByte(); NumberSize = reader.ReadByte(); if (IntSize != 4 || SizeTSize != 4 || InstructionSize != 4 || InstructionOpSize != 6 || InstructionASize != 8 || InstructionBSize != 9 || InstructionCSize != 9 || NumberSize != 8) throw new InvalidDataException(); double constant = ReadNumber(reader); if (constant != 3.14159265358979323846e7) throw new InvalidDataException(); Main = new LuaFunction(reader, this); } }
public LuaFunction(BinaryReader reader, int index, LuaFunction parent) : this(reader, parent.Module) { Index = index; Parent = parent; }