Interface MochaCompiledFunction
- All Known Subinterfaces:
MochaFunction
public interface MochaCompiledFunction
Marker interface for Molang compiled functions.
This interface is supposed to be extended by user-defined interfaces with a single method, that they will be able to call to directly execute the function.
See the following example on compiling a function that computes how a player's level is computed from their experience:
interface PlayerLevelFunction extends MolangFunction {
int computeLevel(@Named("xp") int experience);
}
// ...
MolangCompiler compiler = ...;
PlayerLevelFunction function = compiler.compile("100 * sqrt(xp)", PlayerLevelFunction.class);
// cache "function" and then...
function.computeLevel(100); // 31
Note that all the parameters from the function method must
have a name, they can either be annotated with the Named
annotation or have a name in runtime (Compiler's -parameters flag)
Also note that the function's returned value can take a null-like
value depending on the specified return type. For numbers, it will be
zero, and for objects it will be null
- Since:
- 3.0.0
- See Also: