dan200.computercraft.api.lua.LuaException Java Examples
The following examples show how to use
dan200.computercraft.api.lua.LuaException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuaObjectWrapper.java From OpenPeripheral with MIT License | 6 votes |
@Override public Object[] callMethod(final ILuaContext context, final int index, final Object[] arguments) throws LuaException, InterruptedException { final IMethodExecutor method = methods.getMethod(index); Preconditions.checkNotNull(method, "Invalid method index: %d", index); if (method.isAsynchronous()) return call(index, method, context, arguments); else { Object[] result = SynchronousExecutor.executeInMainThread(context, new SynchronousExecutor.Task() { @Override public Object[] execute() throws LuaException, InterruptedException { return call(index, method, context, arguments); } }); return result; } }
Example #2
Source File: SynchronousExecutor.java From OpenPeripheral with MIT License | 5 votes |
public static Object[] executeInMainThread(ILuaContext context, Task task) throws LuaException, InterruptedException { final Responder responder = new Responder(context, task); long taskId = context.issueMainThreadTask(responder); responder.waitForEvent(taskId); // This code was executed in main thread, so there are no special exceptions we need to pass final Throwable error = responder.error; if (error != null) { if (error instanceof LuaException) throw (LuaException)error; else throw new LuaException(AdapterLogicException.getMessageForThrowable(error)); } return responder.result; }
Example #3
Source File: TileEntityDroneInterface.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override @Optional.Method(modid = ModIds.COMPUTERCRAFT) public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException{ try { return luaMethods.get(method).call(arguments); } catch(Exception e) { throw new LuaException(e.getMessage()); } }
Example #4
Source File: TileEntityBase.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override @Optional.Method(modid = ModIds.COMPUTERCRAFT) public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException{ try { return luaMethods.get(method).call(arguments); } catch(Exception e) { throw new LuaException(e.getMessage()); } }
Example #5
Source File: TileEntityReactorComputerPort.java From BigReactors with MIT License | 5 votes |
@Override @Optional.Method(modid = "ComputerCraft") public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException { try { return callMethod(method, arguments); } catch(Exception e) { // Rethrow errors as LuaExceptions for CC throw new LuaException(e.getMessage()); } }
Example #6
Source File: PeripheralMotor.java From Framez with GNU General Public License v3.0 | 4 votes |
@Override public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException { if (method == 0) { if (arguments.length == 0) throw new LuaException("At least 1 argument is required (face)"); return new Object[] { te.setFace(toFD(arguments[0])) }; } else if (method == 1) { return new Object[] { te.getFace().ordinal() }; } else if (method == 2) { if (!(te.getMovement() instanceof MovementSlide)) throw new LuaException("This is not a slider motor!"); if (arguments.length == 0) throw new LuaException("At least 1 argument is required (direction)"); ((IMovementSlide) te.getMovement()).setDirection(toFD(arguments[0])); return new Object[] {}; } else if (method == 3) { if (!(te.getMovement() instanceof MovementSlide)) throw new LuaException("This is not a slider motor!"); return new Object[] { ((IMovementSlide) te.getMovement()).getDirection().ordinal() }; } else if (method == 4) { throw new LuaException("Not implemented yet, sorry D:"); // if (arguments.length < 2) // throw new LuaException("At least 2 arguments are required (face, direction)"); // // ForgeDirection face = toFD(arguments[0]); // ForgeDirection direction = toFD(arguments[1]); // // if (face == null || direction == null) // throw new LuaException("Invalid directions!"); // if (face == direction || face == direction.getOpposite()) // throw new LuaException("Motors cannot push or pull blocks!"); // // te.setFace(face, true); // te.setDirection(direction, true); // // return new Object[] { true }; } else if (method == 5) { return new Object[] { te.move() }; } return null; }
Example #7
Source File: AdapterPeripheral.java From OpenPeripheral with MIT License | 4 votes |
@Override public Object[] callMethod(final IComputerAccess computer, final ILuaContext context, final int index, final Object[] arguments) throws LuaException, InterruptedException { // this should throw if peripheral isn't attached computer.getAttachmentName(); final IMethodExecutor method = methods.getMethod(index); Preconditions.checkNotNull(method, "Invalid method index: %d", index); final IMethodCall preparedCall = prepareCall(method, computer, context); final Optional<String> returnSignal = method.getReturnSignal(); if (returnSignal.isPresent()) { final int callbackId = SignallingGlobals.instance.nextCallbackId(); final String returnSignalId = returnSignal.get(); if (method.isAsynchronous()) { SignallingGlobals.instance.scheduleTask(new Runnable() { @Override public void run() { computer.queueEvent(returnSignalId, executeToSignal(callbackId, index, preparedCall, arguments)); } }); } else { context.issueMainThreadTask(new ILuaTask() { @Override public Object[] execute() { computer.queueEvent(returnSignalId, executeToSignal(callbackId, index, preparedCall, arguments)); // this will be used as 'task_complete' result, so we will ignore it return NULL; } }); } return new Object[] { callbackId }; } else { if (method.isAsynchronous()) return executeCall(preparedCall, index, arguments); else { Object[] results = SynchronousExecutor.executeInMainThread(context, new SynchronousExecutor.Task() { @Override public Object[] execute() throws LuaException, InterruptedException { return executeCall(preparedCall, index, arguments); } }); return results; } } }
Example #8
Source File: WrappedPeripheral.java From OpenPeripheral-Addons with MIT License | 4 votes |
@Override public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException { return (peripheral != null)? peripheral.callMethod(computer, context, method, arguments) : null; }
Example #9
Source File: ITurtleAccess.java From OpenPeripheral-Addons with MIT License | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #10
Source File: IPeripheral.java From OpenPeripheral with MIT License | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #11
Source File: ITurtleAccess.java From OpenPeripheral with MIT License | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #12
Source File: IPeripheral.java From BigReactors with MIT License | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #13
Source File: ITurtleAccess.java From BigReactors with MIT License | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #14
Source File: IPeripheral.java From OpenPeripheral-Addons with MIT License | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #15
Source File: ITurtleAccess.java From OpenPeripheral-Integration with MIT License | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #16
Source File: IPeripheral.java From PneumaticCraft with GNU General Public License v3.0 | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #17
Source File: ITurtleAccess.java From PneumaticCraft with GNU General Public License v3.0 | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #18
Source File: IPeripheral.java From Framez with GNU General Public License v3.0 | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #19
Source File: ITurtleAccess.java From Framez with GNU General Public License v3.0 | 2 votes |
/** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
Example #20
Source File: IPeripheral.java From OpenPeripheral-Integration with MIT License | 2 votes |
/** * This is called when a lua program on an attached computercraft calls peripheral.call() with * one of the methods exposed by getMethodNames().<br> * <br> * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe * when interacting with minecraft objects. * @param computer The interface to the computercraft that is making the call. Remember that multiple * computers can be attached to a peripheral at once. * @param context The context of the currently running lua thread. This can be used to wait for events * or otherwise yield. * @param method An integer identifying which of the methods from getMethodNames() the computercraft * wishes to call. The integer indicates the index into the getMethodNames() table * that corresponds to the string passed into peripheral.call() * @param arguments An array of objects, representing the arguments passed into peripheral.call().<br> * Lua values of type "string" will be represented by Object type String.<br> * Lua values of type "number" will be represented by Object type Double.<br> * Lua values of type "boolean" will be represented by Object type Boolean.<br> * Lua values of any other type will be represented by a null object.<br> * This array will be empty if no arguments are passed. * @return An array of objects, representing values you wish to return to the lua program.<br> * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br> * All other types will be converted to nil.<br> * You may return null to indicate no values should be returned. * @throws Exception If you throw any exception from this function, a lua error will be raised with the * same message as your exception. Use this to throw appropriate errors if the wrong * arguments are supplied to your method. * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
Example #21
Source File: SynchronousExecutor.java From OpenPeripheral with MIT License | votes |
public Object[] execute() throws LuaException, InterruptedException;