Support for multiple args in file:read

This commit is contained in:
Alessandro Proto 2023-02-26 11:11:09 +01:00
parent e6c70d43a0
commit eb58bdda14

View file

@ -193,14 +193,16 @@ public class FileHandle : IComponent
L.PushString("l"); L.PushString("l");
} }
for (int i = 2; i <= nargs + 1; i++)
{
bool success; bool success;
if (L.Type(2) == LuaType.Number) if (L.Type(i) == LuaType.Number)
{ {
success = ReadChars(L, stream, (int)L.ToNumber(2)); success = ReadChars(L, stream, (int)L.ToNumber(2));
} }
else else
{ {
var p = L.CheckString(2); var p = L.CheckString(i);
var mode = CheckMode(p); var mode = CheckMode(p);
switch (mode) switch (mode)
{ {
@ -218,7 +220,7 @@ public class FileHandle : IComponent
success = true; success = true;
break; break;
default: default:
return L.ArgumentError(2, "invalid format"); return L.ArgumentError(i, "invalid format");
} }
} }
@ -228,8 +230,9 @@ public class FileHandle : IComponent
L.Pop(1); L.Pop(1);
L.PushNil(); L.PushNil();
} }
}
return 1; return nargs;
} }
private static int L_Write(IntPtr state) private static int L_Write(IntPtr state)