1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-07 20:42:53 +00:00

Use longs instead of ints within .seek

Some crazy person decided they wanted a 20GB file. I'm not judging.
This commit is contained in:
SquidDev 2018-11-28 18:02:52 +00:00
parent afdfcb21b7
commit 949b71d40c
2 changed files with 20 additions and 4 deletions

View File

@ -70,12 +70,17 @@ public final class ArgumentHelper
} }
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
{
return (int) getLong( args, index );
}
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "number", "nil" ); if( index >= args.length ) throw badArgument( index, "number", "nil" );
Object value = args[ index ]; Object value = args[ index ];
if( value instanceof Number ) if( value instanceof Number )
{ {
return (int) ((Number) value).longValue(); return checkReal( index, (Number) value ).longValue();
} }
else else
{ {
@ -151,6 +156,11 @@ public final class ArgumentHelper
} }
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
{
return (int) optLong( args, index, def );
}
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[ index ] : null;
if( value == null ) if( value == null )
@ -159,7 +169,7 @@ public final class ArgumentHelper
} }
else if( value instanceof Number ) else if( value instanceof Number )
{ {
return (int) ((Number) value).longValue(); return checkReal( index, (Number) value ).longValue();
} }
else else
{ {
@ -224,6 +234,12 @@ public final class ArgumentHelper
} }
} }
private static Number checkReal( int index, Number value ) throws LuaException
{
checkReal( index, value.doubleValue() );
return value;
}
private static double checkReal( int index, double value ) throws LuaException private static double checkReal( int index, double value ) throws LuaException
{ {
if( Double.isNaN( value ) ) if( Double.isNaN( value ) )

View File

@ -9,7 +9,7 @@ import java.io.IOException;
import java.nio.channels.Channel; import java.nio.channels.Channel;
import java.nio.channels.SeekableByteChannel; import java.nio.channels.SeekableByteChannel;
import static dan200.computercraft.core.apis.ArgumentHelper.optInt; import static dan200.computercraft.core.apis.ArgumentHelper.optLong;
import static dan200.computercraft.core.apis.ArgumentHelper.optString; import static dan200.computercraft.core.apis.ArgumentHelper.optString;
public abstract class HandleGeneric implements ILuaObject public abstract class HandleGeneric implements ILuaObject
@ -54,7 +54,7 @@ public abstract class HandleGeneric implements ILuaObject
try try
{ {
String whence = optString( args, 0, "cur" ); String whence = optString( args, 0, "cur" );
long offset = optInt( args, 1, 0 ); long offset = optLong( args, 1, 0 );
switch( whence ) switch( whence )
{ {
case "set": case "set":