Annotation Interface Binding


@Documented @Target({METHOD,FIELD,TYPE}) @Retention(RUNTIME) public @interface Binding
Gives a name to a type (class, interface, enum), method or field to be used from Molang scripts.

Binding names are concatenated with dots (.) to access nested types, methods or fields.

For example, if you have a class named Foo with a field named bar and a method named baz, you can bind them as follows:

 @Binding("foo")
  class Foo {
     @Binding("baz")
      public static int baz = 0;

     @Binding("bar")
      public static void bar() {}
  }
 

Then, you can access them from Molang scripts as follows:

     foo.baz
     foo.bar()
 

Note that for non-static bindings, the instance name will be used instead.

A class annotated with Binding can also implement

Since:
3.0.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    @NotNull String[]
    Returns the names for this binding.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    (For methods only) Determines if this method is pure or not.
    boolean
    Returns whether this binding should be skipped from the binding checking/normalizing process.
  • Element Details

    • value

      @NotNull @NotNull String[] value
      Returns the names for this binding.
      Returns:
      The names for this binding.
      Since:
      3.0.0
    • skipChecking

      boolean skipChecking
      Returns whether this binding should be skipped from the binding checking/normalizing process.

      For example, functions that return a double value must be checked in order to replace NaN and Infinity values by zero. If a function already does that, then it can be skipped from the automatic process.

      Returns:
      Whether this binding should be skipped from the binding checking/normalizing process.
      Since:
      3.0.0
      Default:
      false
    • pure

      boolean pure
      (For methods only) Determines if this method is pure or not.

      A pure method is a method that has the following properties:

      1. The method return values are identical for identical arguments, and
      2. The method has no side effects

      The compiler or interpreter may pre-evaluate these functions ahead of time. In case of compiling, the function may be called during compile time, to use the function's result instead.

      Returns:
      If this function is pure or not.
      Since:
      3.0.0
      Default:
      false