Annotation Interface LuaFunction


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface LuaFunction
Used to mark a Java function which is callable from Lua.

Methods annotated with LuaFunction must be public final instance methods. They can have any number of parameters, but they must be of the following types:

  • ILuaContext (and IComputerAccess if on a IPeripheral)
  • IArguments: The arguments supplied to this function.
  • Alternatively, one may specify the desired arguments as normal parameters and the argument parsing code will be generated automatically.

    Each parameter must be one of the given types supported by IArguments (for instance, int or Map). Optional values are supported by accepting a parameter of type Optional.

This function may return MethodResult. However, if you simply return a value (rather than having to yield), you may return void, a single value (either an object or a primitive like int) or array of objects. These will be treated the same as MethodResult.of(), MethodResult.of(Object) and MethodResult.of(Object...).

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Run this function on the main server thread.
    boolean
    Allow using "unsafe" arguments, such IArguments.getTableUnsafe(int).
    Explicitly specify the method names of this function.
  • Element Details

    • value

      String[] value
      Explicitly specify the method names of this function. If not given, it uses the name of the annotated method.
      Returns:
      This function's name(s).
      Default:
      {}
    • mainThread

      boolean mainThread
      Run this function on the main server thread. This should be specified for any method which interacts with Minecraft in a thread-unsafe manner.
      Returns:
      Whether this function should be run on the main thread.
      See Also:
      Default:
      false
    • unsafe

      boolean unsafe
      Allow using "unsafe" arguments, such IArguments.getTableUnsafe(int).

      This is incompatible with mainThread().

      Returns:
      Whether this function supports unsafe arguments.
      Default:
      false