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,43 +193,46 @@ public class FileHandle : IComponent
L.PushString("l"); L.PushString("l");
} }
bool success; for (int i = 2; i <= nargs + 1; i++)
if (L.Type(2) == LuaType.Number)
{ {
success = ReadChars(L, stream, (int)L.ToNumber(2)); bool success;
} if (L.Type(i) == LuaType.Number)
else
{
var p = L.CheckString(2);
var mode = CheckMode(p);
switch (mode)
{ {
case 'n': success = ReadChars(L, stream, (int)L.ToNumber(2));
success = ReadNumber(L, stream); }
break; else
case 'l': {
success = ReadLine(L, stream, true); var p = L.CheckString(i);
break; var mode = CheckMode(p);
case 'L': switch (mode)
success = ReadLine(L, stream, false); {
break; case 'n':
case 'a': success = ReadNumber(L, stream);
ReadAll(L, stream); break;
success = true; case 'l':
break; success = ReadLine(L, stream, true);
default: break;
return L.ArgumentError(2, "invalid format"); 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) return nargs;
{
L.Pop(1);
L.PushNil();
}
return 1;
} }
private static int L_Write(IntPtr state) private static int L_Write(IntPtr state)