Skip to content

Instantly share code, notes, and snippets.

@boq
Created March 1, 2015 18:55
Show Gist options
  • Select an option

  • Save boq/f16ad1de64ce6e38ca14 to your computer and use it in GitHub Desktop.

Select an option

Save boq/f16ad1de64ce6e38ca14 to your computer and use it in GitHub Desktop.
package testmod;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
public class FaultyPeripheral implements IPeripheral {
private static class TestObject implements ILuaObject {
@Override
public String[] getMethodNames() {
return new String[] { "a", "b", "c" };
}
@Override
public Object[] callMethod(ILuaContext context, int method, Object[] arguments) {
return new Object[] { "Method: " + method };
}
}
@Override
public String getType() {
return "faulty_peripheral";
}
@Override
public String[] getMethodNames() {
return new String[] { "testSync", "testAsync" };
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException {
switch (method) {
case 0: {
Object[] result = context.executeMainThreadTask(new ILuaTask() {
@Override
public Object[] execute() {
return new Object[] { new TestObject() };
}
});
return result;
}
case 1: {
return new Object[] { new TestObject() };
}
default:
throw new IndexOutOfBoundsException(Integer.toString(method));
}
}
@Override
public void attach(IComputerAccess computer) {}
@Override
public void detach(IComputerAccess computer) {}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment