|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.luaj.vm2.Varargs
org.luaj.vm2.LuaValue
org.luaj.vm2.LuaThread
public class LuaThread
Subclass of LuaValue that implements
a lua coroutine thread using Java Threads.
A LuaThread is typically created in response to a scripted call to
coroutine.create()
The threads must be initialized with the globals, so that
the global environment may be passed along according to rules of lua.
This is done via the constructor arguments LuaThread(Globals) or
LuaThread(Globals, LuaValue).
The utility classes JsePlatform and
JmePlatform
see to it that this Globals are initialized properly.
The behavior of coroutine threads matches closely the behavior of C coroutine library. However, because of the use of Java threads to manage call state, it is possible to yield from anywhere in luaj.
Each Java thread wakes up at regular intervals and checks a weak reference
to determine if it can ever be resumed. If not, it throws
OrphanedThread which is an Error.
Applications should not catch OrphanedThread, because it can break
the thread safety of luaj. The value controlling the polling interval
is thread_orphan_check_interval and may be set by the user.
There are two main ways to abandon a coroutine. The first is to call
yield() from lua, or equivalently Globals.yield(Varargs),
and arrange to have it never resumed possibly by values passed to yield.
The second is to throw OrphanedThread, which should put the thread
in a dead state. In either case all references to the thread must be
dropped, and the garbage collector must run for the thread to be
garbage collected.
LuaValue,
JsePlatform,
JmePlatform,
CoroutineLib| Nested Class Summary | |
|---|---|
static class |
LuaThread.State
|
| Field Summary | |
|---|---|
java.lang.Object |
callstack
Thread-local used by DebugLib to store debugging state. |
static int |
coroutine_count
The current number of coroutines. |
LuaValue |
errorfunc
Error message handler for this thread, if any. |
Globals |
globals
|
static int |
MAX_CALLSTACK
|
static LuaValue |
s_metatable
Shared metatable for lua threads. |
LuaThread.State |
state
|
static int |
STATUS_DEAD
|
static int |
STATUS_INITIAL
|
static java.lang.String[] |
STATUS_NAMES
|
static int |
STATUS_NORMAL
|
static int |
STATUS_RUNNING
|
static int |
STATUS_SUSPENDED
|
static long |
thread_orphan_check_interval
Polling interval, in milliseconds, which each thread uses while waiting to return from a yielded state to check if the lua threads is no longer referenced and therefore should be garbage collected. |
| Fields inherited from class org.luaj.vm2.LuaValue |
|---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
| Constructor Summary | |
|---|---|
LuaThread(Globals globals)
Private constructor for main thread only |
|
LuaThread(Globals globals,
LuaValue func)
Create a LuaThread around a function and environment |
|
| Method Summary | |
|---|---|
LuaThread |
checkthread()
Check that this is a LuaThread, or throw LuaError if it is not |
LuaValue |
getmetatable()
Get the metatable for this LuaValue |
java.lang.String |
getStatus()
|
boolean |
isMainThread()
|
boolean |
isthread()
Check if this is a thread |
LuaThread |
optthread(LuaThread defval)
Check that optional argument is a thread and return as LuaThread |
Varargs |
resume(Varargs args)
|
int |
type()
Get the enumeration value for the type of this value. |
java.lang.String |
typename()
Get the String name of the type of this value. |
| Methods inherited from class org.luaj.vm2.Varargs |
|---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static LuaValue s_metatable
public static int coroutine_count
public static long thread_orphan_check_interval
public static final int STATUS_INITIAL
public static final int STATUS_SUSPENDED
public static final int STATUS_RUNNING
public static final int STATUS_NORMAL
public static final int STATUS_DEAD
public static final java.lang.String[] STATUS_NAMES
public final LuaThread.State state
public static final int MAX_CALLSTACK
public java.lang.Object callstack
public final Globals globals
public LuaValue errorfunc
| Constructor Detail |
|---|
public LuaThread(Globals globals)
public LuaThread(Globals globals,
LuaValue func)
func - The function to execute| Method Detail |
|---|
public int type()
LuaValue
type in class LuaValueLuaValue.TNIL,
LuaValue.TBOOLEAN,
LuaValue.TNUMBER,
LuaValue.TSTRING,
LuaValue.TTABLE,
LuaValue.TFUNCTION,
LuaValue.TUSERDATA,
LuaValue.TTHREADLuaValue.typename()public java.lang.String typename()
LuaValue
typename in class LuaValueLuaValue.TYPE_NAMES
corresponding to the type of this value:
"nil", "boolean", "number", "string",
"table", "function", "userdata", "thread"LuaValue.type()public boolean isthread()
LuaValuethis is a thread
isthread in class LuaValuethread, otherwise falseLuaValue.checkthread(),
LuaValue.optthread(LuaThread),
LuaValue.TTHREADpublic LuaThread optthread(LuaThread defval)
LuaValueLuaThread
optthread in class LuaValuedefval - LuaThread to return if this is nil or none
this cast to LuaTable if a thread,
defval if nil or none,
throws LuaError if some other typeLuaValue.checkthread(),
LuaValue.isthread(),
LuaValue.TTHREADpublic LuaThread checkthread()
LuaValueLuaThread, or throw LuaError if it is not
checkthread in class LuaValuethis if it is a LuaThreadLuaValue.isthread(),
LuaValue.optthread(LuaThread),
LuaValue.TTHREADpublic LuaValue getmetatable()
LuaValueLuaValue
For LuaTable and LuaUserdata instances,
the metatable returned is this instance metatable.
For all other types, the class metatable value will be returned.
getmetatable in class LuaValueLuaBoolean.s_metatable,
LuaNumber.s_metatable,
LuaNil.s_metatable,
LuaFunction.s_metatable,
s_metatablepublic java.lang.String getStatus()
public boolean isMainThread()
public Varargs resume(Varargs args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||