From eb58bdda1403be19365c9376911cb1b63becec55 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Sun, 26 Feb 2023 11:11:09 +0100 Subject: [PATCH] Support for multiple args in file:read --- Capy64/Runtime/Objects/FileHandle.cs | 65 +++++++++++++++------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/Capy64/Runtime/Objects/FileHandle.cs b/Capy64/Runtime/Objects/FileHandle.cs index f5b3de0..870cccd 100644 --- a/Capy64/Runtime/Objects/FileHandle.cs +++ b/Capy64/Runtime/Objects/FileHandle.cs @@ -193,43 +193,46 @@ public class FileHandle : IComponent L.PushString("l"); } - bool success; - if (L.Type(2) == LuaType.Number) + for (int i = 2; i <= nargs + 1; i++) { - success = ReadChars(L, stream, (int)L.ToNumber(2)); - } - else - { - var p = L.CheckString(2); - var mode = CheckMode(p); - switch (mode) + bool success; + if (L.Type(i) == LuaType.Number) { - case 'n': - success = ReadNumber(L, stream); - break; - case 'l': - success = ReadLine(L, stream, true); - break; - case 'L': - success = ReadLine(L, stream, false); - break; - case 'a': - ReadAll(L, stream); - success = true; - break; - default: - return L.ArgumentError(2, "invalid format"); + success = ReadChars(L, stream, (int)L.ToNumber(2)); + } + else + { + var p = L.CheckString(i); + var mode = CheckMode(p); + switch (mode) + { + case 'n': + success = ReadNumber(L, stream); + break; + case 'l': + success = ReadLine(L, stream, true); + break; + case 'L': + success = ReadLine(L, stream, false); + break; + case 'a': + ReadAll(L, stream); + success = true; + break; + default: + return L.ArgumentError(i, "invalid format"); + } + } + if (!success) + { + L.Pop(1); + L.PushNil(); + } } - if (!success) - { - L.Pop(1); - L.PushNil(); - } - - return 1; + return nargs; } private static int L_Write(IntPtr state)