public interface ExecutionContext extends StateContext
This is the interface to the runtime environment in which Lua calls are executed, providing the mechanisms for including coroutine switching and the (optional) cooperative scheduler.
Note: Lua functions are not guaranteed to receive the same
ExecutionContext
instance between an invoke and a subsequent resume.
Functions should therefore not retain the reference to the ExecutionContext
that outlives an invoke
or resume
.
Note: The behaviour of the methods in this interface is undefined when invoked outside a Lua function invoke/resume.
Modifier and Type | Method and Description |
---|---|
Coroutine.Status |
getCoroutineStatus(Coroutine coroutine)
Returns the status of
coroutine as seen from the perspective of this execution
context. |
Coroutine |
getCurrentCoroutine()
Returns the current coroutine.
|
ReturnBuffer |
getReturnBuffer()
Returns the return buffer used in this execution context.
|
boolean |
isInMainCoroutine()
Returns
true if the current coroutine (as returned
by getCurrentCoroutine() ) is the main coroutine. |
Coroutine |
newCoroutine(LuaFunction function)
Returns a new coroutine with the body
function . |
void |
pause()
(Unconditionally) pauses the execution.
|
void |
pauseIfRequested()
Pauses the execution if the according to the scheduler this call should be paused.
|
void |
registerTicks(int ticks)
Informs the scheduler that the current task is about to consume or has consumed
ticks virtual ticks. |
void |
resume(Coroutine coroutine,
Object[] args)
Resumes the given coroutine
coroutine , passing the arguments args
to it. |
void |
resumeAfter(AsyncTask task)
Resumes the current call after the asynchronous task
task has been completed. |
void |
yield(Object[] args)
Yields control to the coroutine resuming the current coroutine, passing the
arguments
args to it. |
setBooleanMetatable, setFunctionMetatable, setLightUserdataMetatable, setMetatable, setNilMetatable, setNumberMetatable, setStringMetatable, setThreadMetatable
getBooleanMetatable, getFunctionMetatable, getLightUserdataMetatable, getMetatable, getNilMetatable, getNumberMetatable, getStringMetatable, getThreadMetatable
newTable, newTable
ReturnBuffer getReturnBuffer()
This is the mechanism by which Lua functions may return values (see e.g.
ReturnBuffer.setToContentsOf(Object[])
), or indicate that the return
value is the result of a tail call (by e.g.
ReturnBuffer.setToCallWithContentsOf(Object, Object[])
).
The return values of Lua calls initiated from this execution context will
also be stored in a return buffer accessible by this method (e.g. by
ReturnBuffer.getAsArray()
or ReturnBuffer.get(int)
).
Note: the return buffer instance may change between subsequent invokes
and resumes of the same function. The reference to the ReturnBuffer
instance
should therefore not be retained by the executed function beyond the scope of a single
invoke or resume.
Coroutine getCurrentCoroutine()
boolean isInMainCoroutine()
true
if the current coroutine (as returned
by getCurrentCoroutine()
) is the main coroutine.true
if the current coroutine is the main coroutineCoroutine.Status getCoroutineStatus(Coroutine coroutine)
coroutine
as seen from the perspective of this execution
context.coroutine
- the target coroutine, must not be null
coroutine
from the perspective of this execution contextNullPointerException
- if coroutine
is null
Coroutine newCoroutine(LuaFunction function)
function
.
The coroutine will be initialised in the suspended state. To resume the coroutine, use resume(Coroutine, Object[])
.
function
- coroutine body, must not be null
function
NullPointerException
- if function
is null
void resume(Coroutine coroutine, Object[] args) throws UnresolvedControlThrowable
coroutine
, passing the arguments args
to it.
This method throws an UnresolvedControlThrowable
: non-local control
changes are expected to be resolved by the caller of this method.
The reference to the array args
is not retained by the execution context;
args
may therefore be freely re-used by the caller.
coroutine
- the coroutine to be resumed, must not be null
args
- arguments to be passed to coroutine
, must not be null
UnresolvedControlThrowable
- the control throwable for this coroutine switchNullPointerException
- if coroutine
or args
is null
IllegalCoroutineStateException
- when coroutine
cannot be resumedvoid yield(Object[] args) throws UnresolvedControlThrowable
args
to it.
This method throws an UnresolvedControlThrowable
: non-local control
changes are expected to be resolved by the caller of this method.
The reference to the array args
is not retained by the execution context;
args
may therefore be freely re-used by the caller.
args
- arguments to be passed to the resuming coroutine, must not be null
UnresolvedControlThrowable
- the control throwable for this coroutine switchNullPointerException
- if args
is null
IllegalCoroutineStateException
- when yielding from a non-yieldable coroutinevoid resumeAfter(AsyncTask task) throws UnresolvedControlThrowable
task
has been completed.
This method throws an UnresolvedControlThrowable
: non-local control
changes are expected to be resolved by the caller of this method.
In order to mark task
as completed, the task must call
AsyncTask.ContinueCallback.finished()
.
task
- the task to be executed, must not be null
UnresolvedControlThrowable
- the control throwable for this control changeNullPointerException
- if task
is null
void registerTicks(int ticks)
ticks
virtual ticks.
This method only registers ticks
with the scheduler. In order to pause
the execution if the scheduler indicates that it should be paused, use
pauseIfRequested()
.
The behaviour of this method is undefined if ticks
is negative.
ticks
- number of ticks to be registered with the scheduler, must not be negativevoid pauseIfRequested() throws UnresolvedControlThrowable
UnresolvedControlThrowable
: non-local control
changes are expected to be resolved by the caller of this method.
To pause execution unconditionally, use pause()
.
UnresolvedControlThrowable
- the control throwable for this control changevoid pause() throws UnresolvedControlThrowable
UnresolvedControlThrowable
: non-local control
changes are expected to be resolved by the caller of this method.UnresolvedControlThrowable
- the control throwable for this control changeCopyright © 2016. All rights reserved.