Package dan200.computercraft.api.lua
Annotation 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
(andIComputerAccess
if on aIPeripheral
)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
orMap
). Optional values are supported by accepting a parameter of typeOptional
.
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 ElementsModifier and TypeOptional ElementDescriptionboolean
Run this function on the main server thread.boolean
Allow using "unsafe" arguments, suchIArguments.getTableUnsafe(int)
.String[]
Explicitly specify the method names of this function.
-
Element Details
-
value
String[] valueExplicitly 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 mainThreadRun 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 unsafeAllow using "unsafe" arguments, suchIArguments.getTableUnsafe(int)
.This is incompatible with
mainThread()
.- Returns:
- Whether this function supports unsafe arguments.
- Default:
- false
-