Interface IDynamicPeripheral

All Superinterfaces:
IPeripheral

public interface IDynamicPeripheral extends IPeripheral
A peripheral whose methods are not known at runtime.

This behaves similarly to IDynamicLuaObject, though also accepting the current IComputerAccess. Generally one may use LuaFunction instead of implementing this interface.

  • Method Details

    • getMethodNames

      String[] getMethodNames()
      Should return an array of strings that identify the methods that this peripheral exposes to Lua. This will be called once before each attachment, and should not change when called multiple times.
      Returns:
      An array of strings representing method names.
      See Also:
    • callMethod

      MethodResult callMethod(IComputerAccess computer, ILuaContext context, int method, IArguments arguments) throws LuaException
      This is called when a lua program on an attached computer calls peripheral.call() with one of the methods exposed by getMethodNames().

      Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe when interacting with Minecraft objects.

      Parameters:
      computer - The interface to the computer that is making the call. Remember that multiple computers can be attached to a peripheral at once.
      context - The context of the currently running lua thread. This can be used to wait for events or otherwise yield.
      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()
      arguments - The arguments for this method.
      Returns:
      A MethodResult containing the values to return or the action to perform.
      Throws:
      LuaException - 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 Also: