diff --git a/Capy64/Runtime/Objects/Handlers/BinaryReadHandle.cs b/Capy64/Runtime/Objects/Handlers/BinaryReadHandle.cs index d610f2d..6f4a470 100644 --- a/Capy64/Runtime/Objects/Handlers/BinaryReadHandle.cs +++ b/Capy64/Runtime/Objects/Handlers/BinaryReadHandle.cs @@ -12,6 +12,7 @@ public class BinaryReadHandle private static readonly Dictionary functions = new() { + ["readAll"] = L_ReadAll, ["nextByte"] = L_NextByte, ["nextShort"] = L_NextShort, ["nextInt"] = L_NextInt, @@ -56,6 +57,25 @@ public class BinaryReadHandle L.SetMetaTable(-2); } + private static int L_ReadAll(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var stream = L.CheckObject(1, ObjectType, false); + + if (stream is null) + L.Error("handle is closed"); + + if (stream.BaseStream.Position == stream.BaseStream.Length) + return 0; + + var chars = stream.ReadChars((int)stream.BaseStream.Length); + var buffer = Encoding.ASCII.GetBytes(chars); + + L.PushBuffer(buffer); + return 1; + } + private static int L_NextByte(IntPtr state) { var L = Lua.FromIntPtr(state);