mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-25 22:53:22 +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:
parent
afdfcb21b7
commit
949b71d40c
|
@ -70,12 +70,17 @@ public static double getNumber( @Nonnull Object[] args, int index ) throws LuaEx
|
|||
}
|
||||
|
||||
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" );
|
||||
Object value = args[ index ];
|
||||
if( value instanceof Number )
|
||||
{
|
||||
return (int) ((Number) value).longValue();
|
||||
return checkReal( index, (Number) value ).longValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,6 +156,11 @@ else if( value instanceof Number )
|
|||
}
|
||||
|
||||
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;
|
||||
if( value == null )
|
||||
|
@ -159,7 +169,7 @@ public static int optInt( @Nonnull Object[] args, int index, int def ) throws Lu
|
|||
}
|
||||
else if( value instanceof Number )
|
||||
{
|
||||
return (int) ((Number) value).longValue();
|
||||
return checkReal( index, (Number) value ).longValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -224,6 +234,12 @@ else if( value instanceof Map )
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if( Double.isNaN( value ) )
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import java.nio.channels.Channel;
|
||||
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;
|
||||
|
||||
public abstract class HandleGeneric implements ILuaObject
|
||||
|
@ -54,7 +54,7 @@ protected static Object[] handleSeek( SeekableByteChannel channel, Object[] args
|
|||
try
|
||||
{
|
||||
String whence = optString( args, 0, "cur" );
|
||||
long offset = optInt( args, 1, 0 );
|
||||
long offset = optLong( args, 1, 0 );
|
||||
switch( whence )
|
||||
{
|
||||
case "set":
|
||||
|
|
Loading…
Reference in New Issue
Block a user