1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-28 08:03:21 +00:00

Better Code

This commit is contained in:
Wilma456 (Jakob0815) 2017-09-18 15:22:44 +02:00 committed by GitHub
parent 5be2202b2e
commit f20a7afa7f

View File

@ -5,6 +5,7 @@
import javax.annotation.Nonnull;
import java.io.*;
import java.util.Arrays;
import static dan200.computercraft.core.apis.ArgumentHelper.*;
@ -110,22 +111,16 @@ public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull O
checkOpen();
try
{
double count = optNumber( args, 0, 1 );
StringBuilder result = new StringBuilder( "" );
for ( int i = 1; i < count+1; i++ ) {
int character = m_reader.read();
if ( character == -1 ) {
if ( result.length() == 0 ) {
return null;
}
else {
return new Object[] { result.toString() };
}
}
char c = (char) character;
result.append( c );
int count = optInt( args, 0, 1 );
if( count <= 0 || count >= 1024 * 16 )
{
throw new LuaException( "Count out of range" );
}
return new Object[] { result.toString() };
char[] bytes = new char[ count ];
count = m_reader.read( bytes );
if( count < 0 ) return null;
String str = new String( bytes );
return new Object[] { str };
}
catch( IOException e )
{