dan200.computer.api
Interface ILuaContext


public interface ILuaContext

An interface passed to peripherals and ILuaObjects' 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.


Method Summary
 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(), except "terminated" events are ignored.
 java.lang.Object[] yield(java.lang.Object[] arguments)
          Yield the current coroutine with some arguments until it is resumed.
 

Method Detail

pullEvent

java.lang.Object[] pullEvent(java.lang.String filter)
                             throws java.lang.Exception,
                                    java.lang.InterruptedException
Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua.

Parameters:
filter - A specific event to wait for, or null to wait for any event
Returns:
An object array containing the name of the event that occurred, and any event parameters
Throws:
java.lang.Exception - 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 block this exception, unless you wish to prevent termination, which is not recommended.
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.

pullEventRaw

java.lang.Object[] pullEventRaw(java.lang.String filter)
                                throws java.lang.InterruptedException
The same as pullEvent(), 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.

Parameters:
filter - A specific event to wait for, or null to wait for any event
Returns:
An object array containing the name of the event that occurred, and any event parameters
Throws:
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.
See Also:
pullEvent(String)

yield

java.lang.Object[] yield(java.lang.Object[] arguments)
                         throws java.lang.InterruptedException
Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events.

Parameters:
arguments - An object array containing the arguments to pass to coroutine.yield()
Returns:
An object array containing the return values from coroutine.yield()
Throws:
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.
See Also:
pullEvent(String)