Class MethodResult
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 Summary
Modifier and TypeMethodDescriptionadjustError
(int adjust) Increase the Lua error by a specific amount.@Nullable ILuaCallback
int
@Nullable Object @Nullable []
static MethodResult
of()
Return no values immediately.static MethodResult
Return a single value immediately.static MethodResult
Return any number of values immediately.static MethodResult
pullEvent
(@Nullable String filter, ILuaCallback callback) Wait for an event to occur on the computer, suspending the thread until it arises.static MethodResult
pullEventRaw
(@Nullable String filter, ILuaCallback callback) The same aspullEvent(String, ILuaCallback)
, except "terminated" events are ignored.static MethodResult
yield
(@Nullable Object @Nullable [] arguments, ILuaCallback callback) Yield the current coroutine with some arguments until it is resumed.
-
Method Details
-
of
Return no values immediately.- Returns:
- A method result which returns immediately with no values.
-
of
Return a single value immediately.Integers, doubles, floats, strings, booleans,
Map
,Collection
s, arrays andnull
will be converted to their corresponding Lua type.byte[]
andByteBuffer
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 withLuaFunction
annotations. Anything else will be converted tonil
.Shared objects in a
MethodResult
will preserve their sharing when converted to Lua values. For instance,Map<?, ?> m = new HashMap(); return MethodResult.of(m, m);
will return two valuesa
,b
wherea == b
. The one exception to this is Java's singleton collections (List.of()
,Set.of()
andMap.of()
), which are always converted to new table. This is not true for other singleton collections, such as those provided byCollections
or Guava.- Parameters:
value
- The value to return to the calling Lua function.- Returns:
- A method result which returns immediately with the given value.
-
of
Return any number of values immediately.- Parameters:
values
- The values to return. Seeof(Object)
for acceptable values.- Returns:
- A method result which returns immediately with the given values.
-
pullEvent
Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent toos.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
The same aspullEvent(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 toos.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
Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent tocoroutine.yield()
in lua. UsepullEvent()
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
-
getCallback
-
getErrorAdjust
public int getErrorAdjust() -
adjustError
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.
-