Package dan200.computercraft.api.lua
Interface ILuaContext
public interface ILuaContext
An interface passed to peripherals and
IDynamicLuaObject
s by computers or turtles, providing methods
that allow the peripheral call to interface with the computer.-
Method Summary
Modifier and TypeMethodDescriptiondefault MethodResult
executeMainThreadTask
(LuaTask 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
(LuaTask 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.
-
Method Details
-
issueMainThreadTask
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. This should be used when you need to interact with the world in a thread-safe manner but do not care about the result or you wish to run asynchronously.When the task has finished, it will enqueue a
task_completed
event, which takes the task id, a success value and the return values, or an error message if it failed.- Parameters:
task
- The task to execute on the main thread.- Returns:
- The "id" of the task. This will be the first argument to the
task_completed
event. - Throws:
LuaException
- If the task could not be queued.- See Also:
-
executeMainThreadTask
Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete. This should be used when you need to interact with the world in a thread-safe manner.Note that the return values of your task are handled as events, meaning more complex objects such as maps or
IDynamicLuaObject
will not preserve their identities.- Parameters:
task
- The task to execute on the main thread.- Returns:
- The objects returned by
task
. - Throws:
LuaException
- If the task could not be queued, or if the task threw an exception.
-