public class CoronaRuntimeTaskDispatcher extends Object
CoronaRuntime's
thread, just before Corona
renders a frame. These tasks provide thread safe access to the CoronaRuntime
and its
LuaState
.
The main intention of this class is to provide a means for other threads to invoke Lua functions or
manipulate Lua global variables belonging to the CoronaRuntime's
LuaState
. This is done by implementing the LuaState
manipulation code
within a CoronaRuntimeTask
object and then sending that task object
to the CoronaRuntime
via this class'
send()
method. This class will handle
this in a thread safe manner and make sure that the task object is executed on the
CoronaRuntime's
thread, just before it renders a frame.
Instances of this class are immutable.
CoronaRuntime
,
CoronaRuntimeTask
Constructor and Description |
---|
CoronaRuntimeTaskDispatcher(CoronaRuntime runtime)
Creates a new dispatcher which will send tasks to the given
CoronaRuntime . |
CoronaRuntimeTaskDispatcher(LuaState luaState)
Creates a new dispatcher which will send tasks to the
CoronaRuntime that owns the given
LuaState . |
Modifier and Type | Method and Description |
---|---|
boolean |
isRuntimeAvailable()
Determines if the targeted
CoronaRuntime is still available for this dispatcher to send
tasks to. |
boolean |
isRuntimeUnavailable()
Determines if the targeted
CoronaRuntime is permanently unavailable, meaning that this
dispatcher no longer has a CoronaRuntime to send tasks to. |
void |
send(CoronaRuntimeTask task)
Sends the given task to the
CoronaRuntime to be executed just before it renders a frame. |
public CoronaRuntimeTaskDispatcher(CoronaRuntime runtime)
CoronaRuntime
.runtime
- Reference to the CoronaRuntime
that this dispatcher will send tasks to.
Setting this to null is allowed, but will create a dispatcher that is permanently inactive.
The created dispatcher will also be permanently inactive if the given
CoronaRuntime
has already been disposed/destroyed, which you can check by
calling the CoronaRuntime's
wasDiposed()
method.
The CoronaRuntime
will be disposed when its associated
CoronaActivity
has been destroyed.
You can check if the created dispatcher is capable of sending tasks to the targeted
CoronaRuntime
by calling its
isRuntimeAvailable()
method.
public CoronaRuntimeTaskDispatcher(LuaState luaState)
CoronaRuntime
that owns the given
LuaState
.luaState
- Reference to the LuaState
that is owned by the
CoronaRuntime
that you want to target.
Setting this to null is allowed, but will create a dispatcher that is permanently inactive.
The created dispatcher will also be permanently inactive if the given
CoronaRuntime
has already been disposed/destroyed, which you can check by
calling the CoronaRuntime's
wasDiposed()
method.
The CoronaRuntime
will be disposed when its associated
CoronaActivity
has been destroyed.
You can check if the created dispatcher is capable of sending tasks to the targeted
CoronaRuntime
by calling its
isRuntimeAvailable()
method.
public boolean isRuntimeAvailable()
CoronaRuntime
is still available for this dispatcher to send
tasks to.CoronaRuntime
is still available for this dispatcher to send
tasks to.
Returns false if the CoronaRuntime
has been disposed/destroyed, which happens when
its associated CoronaActivity
has been destroyed. This permanently disables this
dispatcher.
public boolean isRuntimeUnavailable()
CoronaRuntime
is permanently unavailable, meaning that this
dispatcher no longer has a CoronaRuntime
to send tasks to.CoronaRuntime
has been disposed/destroyed, which happens when
its associated CoronaActivity
has been destroyed. This permanently disables this
dispatcher.
Returns false if the CoronaRuntime
is still available.
public void send(CoronaRuntimeTask task)
CoronaRuntime
to be executed just before it renders a frame.
This task will be executed on the same thread that the CoronaRuntime
runs in.
The main intent of this method is to allow another thread to call a Lua function or
manipulate a global variable in the LuaState
on the same thread that Lua is running in.
Tasks will be executed by the CoronaRuntime
in the order that they were sent by this method.
task
- The task to be executed by the CoronaRuntime
.
Setting this to null will cause an exception
to be thrown.