Permalink
Browse files

Migrate ComputerCraft's peripherals/APIs to use the non-blocking API

This is definitely a little ugly in places, mostly due to how we've
handled backwards compatibility.
  • Loading branch information...
SquidDev committed Sep 9, 2018
1 parent 3b4c1ea commit ac8444b364c08149b7ada09d0d385b170cf48fd8
Showing with 614 additions and 603 deletions.
  1. +15 −3 src/main/java/dan200/computercraft/core/apis/BitAPI.java
  2. +30 −13 src/main/java/dan200/computercraft/core/apis/BufferAPI.java
  3. +41 −29 src/main/java/dan200/computercraft/core/apis/FSAPI.java
  4. +18 −6 src/main/java/dan200/computercraft/core/apis/HTTPAPI.java
  5. +0 −245 src/main/java/dan200/computercraft/core/apis/HTTPRequest.java
  6. +35 −24 src/main/java/dan200/computercraft/core/apis/OSAPI.java
  7. +20 −8 src/main/java/dan200/computercraft/core/apis/PeripheralAPI.java
  8. +25 −13 src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java
  9. +32 −22 src/main/java/dan200/computercraft/core/apis/TermAPI.java
  10. +12 −10 src/main/java/dan200/computercraft/core/apis/handles/BinaryInputHandle.java
  11. +9 −7 src/main/java/dan200/computercraft/core/apis/handles/BinaryOutputHandle.java
  12. +15 −13 src/main/java/dan200/computercraft/core/apis/handles/EncodedInputHandle.java
  13. +10 −8 src/main/java/dan200/computercraft/core/apis/handles/EncodedOutputHandle.java
  14. +12 −0 src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java
  15. +15 −7 src/main/java/dan200/computercraft/core/apis/http/HTTPRequest.java
  16. +25 −13 src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java
  17. +21 −11 src/main/java/dan200/computercraft/shared/computer/blocks/ComputerPeripheral.java
  18. +22 −10 src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java
  19. +33 −20 src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java
  20. +22 −10 src/main/java/dan200/computercraft/shared/peripheral/modem/ModemPeripheral.java
  21. +12 −10 src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java
  22. +40 −25 src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorPeripheral.java
  23. +23 −11 src/main/java/dan200/computercraft/shared/peripheral/printer/PrinterPeripheral.java
  24. +22 −16 src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java
  25. +18 −6 src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java
  26. +64 −52 src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java
  27. +1 −0 src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java
  28. +21 −9 src/main/java/dan200/computercraft/shared/turtle/upgrades/CraftingTablePeripheral.java
  29. +1 −2 src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java
@@ -6,10 +6,13 @@
package dan200.computercraft.core.apis;
import dan200.computercraft.api.lua.ICallContext;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.MethodResult;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
@@ -62,8 +65,9 @@ public void shutdown( )
};
}
@Nonnull
@Override
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException
public MethodResult callMethod( @Nonnull ICallContext context, int method, @Nonnull Object[] args ) throws LuaException
{
int ret = 0;
switch(method) {
@@ -89,7 +93,15 @@ public void shutdown( )
ret = getInt( args, 0 ) >>> getInt( args, 1 );
break;
}
return new Object[]{ ret&0xFFFFFFFFL };
return MethodResult.of( ret & 0xFFFFFFFFL );
}
@Nullable
@Override
@Deprecated
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
{
return callMethod( (ICallContext) context, method, arguments ).evaluate( context );
}
}
@@ -6,12 +6,11 @@
package dan200.computercraft.core.apis;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaObject;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.core.terminal.TextBuffer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
import static dan200.computercraft.core.apis.ArgumentHelper.optInt;
@@ -40,27 +39,28 @@ public BufferLuaObject( TextBuffer buffer )
};
}
@Nonnull
@Override
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
public MethodResult callMethod( @Nonnull ICallContext context, int method, @Nonnull Object[] arguments ) throws LuaException
{
switch( method )
{
case 0:
{
// len
return new Object[] { m_buffer.length() };
return MethodResult.of( m_buffer.length() );
}
case 1:
{
// tostring
return new Object[] { m_buffer.toString() };
return MethodResult.of( m_buffer.toString() );
}
case 2:
{
// read
int start = optInt( arguments, 0, 0 );
int end = optInt( arguments, 1, m_buffer.length() );
return new Object[] { m_buffer.read( start, end ) };
return MethodResult.of( m_buffer.read( start, end ) );
}
case 3:
{
@@ -69,7 +69,7 @@ public BufferLuaObject( TextBuffer buffer )
int start = optInt( arguments, 1, 0 );
int end = optInt( arguments, 2, start + text.length() );
m_buffer.write( text, start, end );
return null;
return MethodResult.empty();
}
case 4:
{
@@ -78,14 +78,22 @@ public BufferLuaObject( TextBuffer buffer )
int start = optInt( arguments, 1, 0 );
int end = optInt( arguments, 2, m_buffer.length() );
m_buffer.fill( text, start, end );
return null;
return MethodResult.empty();
}
default:
{
return null;
return MethodResult.empty();
}
}
}
@Nullable
@Override
@Deprecated
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
{
return callMethod( (ICallContext) context, method, arguments ).evaluate( context );
}
}
public BufferAPI( IAPIEnvironment _env )
@@ -124,8 +132,9 @@ public void shutdown()
};
}
@Nonnull
@Override
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
public MethodResult callMethod( @Nonnull ICallContext context, int method, @Nonnull Object[] arguments ) throws LuaException
{
switch( method )
{
@@ -138,12 +147,20 @@ public void shutdown()
throw ArgumentHelper.badArgument( 1, "positive number", Integer.toString( repetitions ) );
}
TextBuffer buffer = new TextBuffer( text, repetitions );
return new Object[] { new BufferLuaObject( buffer ) };
return MethodResult.of( new BufferLuaObject( buffer ) );
}
default:
{
return null;
return MethodResult.empty();
}
}
}
@Nullable
@Override
@Deprecated
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
{
return callMethod( (ICallContext) context, method, arguments ).evaluate( context );
}
}
Oops, something went wrong.

0 comments on commit ac8444b

Please sign in to comment.