public interface ILuaContext
ILuaObject
s by computers or turtles, providing methods
that allow the peripheral call to wait for events before returning, just like in lua. This is very useful if you need
to signal work to be performed on the main thread, and don't want to return until the work has been completed.Modifier and Type | Method and Description |
---|---|
java.lang.Object[] |
executeMainThreadTask(ILuaTask task)
Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete.
|
long |
issueMainThreadTask(ILuaTask task)
Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to
complete.
|
java.lang.Object[] |
pullEvent(java.lang.String filter)
Wait for an event to occur on the computer, suspending the thread until it arises.
|
java.lang.Object[] |
pullEventRaw(java.lang.String filter)
The same as
pullEvent(String) , except "terminated" events are ignored. |
java.lang.Object[] |
yield(java.lang.Object[] arguments)
Yield the current coroutine with some arguments until it is resumed.
|
java.lang.Object[] pullEvent(java.lang.String filter) throws LuaException, java.lang.InterruptedException
os.pullEvent()
in lua.filter
- A specific event to wait for, or null to wait for any event.LuaException
- If the user presses CTRL+T to terminate the current program while pullEvent() is
waiting for an event, a "Terminated" exception will be thrown here.
Do not attempt to catch this exception. You should use pullEventRaw(String)
should you wish to disable termination.java.lang.InterruptedException
- If the user shuts down or reboots the computer while pullEvent() is waiting for an
event, InterruptedException will be thrown. This exception must not be caught or
intercepted, or the computer will leak memory and end up in a broken state.java.lang.Object[] pullEventRaw(java.lang.String filter) throws java.lang.InterruptedException
pullEvent(String)
, except "terminated" events are ignored. Only use this if you want to
prevent program termination, which is not recommended. This method is exactly equivalent to
os.pullEventRaw()
in lua.filter
- A specific event to wait for, or null to wait for any event.java.lang.InterruptedException
- If the user shuts down or reboots the computer while pullEventRaw() is waiting for
an event, InterruptedException will be thrown. This exception must not be caught or
intercepted, or the computer will leak memory and end up in a broken state.pullEvent(String)
java.lang.Object[] yield(java.lang.Object[] arguments) throws java.lang.InterruptedException
coroutine.yield()
in lua. Use pullEvent()
if you wish to wait for events.arguments
- An object array containing the arguments to pass to coroutine.yield()java.lang.InterruptedException
- If the user shuts down or reboots the computer the coroutine is suspended,
InterruptedException will be thrown. This exception must not be caught or
intercepted, or the computer will leak memory and end up in a broken state.pullEvent(String)
java.lang.Object[] executeMainThreadTask(ILuaTask task) throws LuaException, java.lang.InterruptedException
ILuaObject
will not preserve their identities.task
- The task to execute on the main thread.task
.LuaException
- If the task could not be queued, or if the task threw an exception.java.lang.InterruptedException
- If the user shuts down or reboots the computer the coroutine is suspended,
InterruptedException will be thrown. This exception must not be caught or
intercepted, or the computer will leak memory and end up in a broken state.long issueMainThreadTask(ILuaTask task) throws LuaException
task_completed
event, which takes the task id, a success
value and the return values, or an error message if it failed. If you need to wait on this event, it may be
better to use executeMainThreadTask(ILuaTask)
.task
- The task to execute on the main thread.task_completed
event.LuaException
- If the task could not be queued.