Class MethodResult

java.lang.Object
dan200.computercraft.api.lua.MethodResult

public final class MethodResult extends Object
The result of invoking a Lua method.

Method results either return a value immediately (of(Object...) or yield control to the parent coroutine. When the current coroutine is resumed, we invoke the provided ILuaCallback.resume(Object[]) callback.

  • Method Details

    • of

      public static MethodResult of()
      Return no values immediately.
      Returns:
      A method result which returns immediately with no values.
    • of

      public static MethodResult of(@Nullable Object value)
      Return a single value immediately.

      Integers, doubles, floats, strings, booleans, Map, Collections, arrays and null will be converted to their corresponding Lua type. byte[] and ByteBuffer will be treated as binary strings. ILuaFunction will be treated as a function.

      In order to provide a custom object with methods, one may return a IDynamicLuaObject, or an arbitrary class with LuaFunction annotations. Anything else will be converted to nil.

      Parameters:
      value - The value to return to the calling Lua function.
      Returns:
      A method result which returns immediately with the given value.
    • of

      public static MethodResult of(@Nullable Object... values)
      Return any number of values immediately.
      Parameters:
      values - The values to return. See of(Object) for acceptable values.
      Returns:
      A method result which returns immediately with the given values.
    • pullEvent

      public static MethodResult pullEvent(@Nullable String filter, ILuaCallback callback)
      Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua.
      Parameters:
      filter - A specific event to wait for, or null to wait for any event.
      callback - The callback to resume with the name of the event that occurred, and any event parameters.
      Returns:
      The method result which represents this yield.
      See Also:
    • pullEventRaw

      public static MethodResult pullEventRaw(@Nullable String filter, ILuaCallback callback)
      The same as pullEvent(String, ILuaCallback), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in Lua.
      Parameters:
      filter - A specific event to wait for, or null to wait for any event.
      callback - The callback to resume with the name of the event that occurred, and any event parameters.
      Returns:
      The method result which represents this yield.
      See Also:
    • yield

      public static MethodResult yield(@Nullable Object[] arguments, ILuaCallback callback)
      Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events.
      Parameters:
      arguments - An object array containing the arguments to pass to coroutine.yield()
      callback - The callback to resume with an array containing the return values from coroutine.yield()
      Returns:
      The method result which represents this yield.
      See Also:
    • getResult

      @Nullable public Object[] getResult()
    • getCallback

      @Nullable public ILuaCallback getCallback()
    • getErrorAdjust

      public int getErrorAdjust()
    • adjustError

      public MethodResult adjustError(int adjust)
      Increase the Lua error by a specific amount. One should never need to use this function - it largely exists for some CC internal code.
      Parameters:
      adjust - The amount to increase the level by.
      Returns:
      The new MethodResult with an adjusted error. This has no effect on immediate results.