public class LuaThread extends LuaValue
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
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,
CoroutineLib| 限定符和类型 | 类和说明 |
|---|---|
static class |
LuaThread.State |
| 限定符和类型 | 字段和说明 |
|---|---|
DebugLib.CallStack |
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 |
LuaTable |
registry |
static LuaValue |
s_metatable
Shared metatable for lua threads.
|
LuaThread.State |
state |
static int |
STATUS_DEAD |
static int |
STATUS_INITIAL |
static 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.
|
ADD, BAND, BNOT, BOR, BXOR, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, IDIV, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SHL, SHR, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, uservalue, ZERO| 构造器和说明 |
|---|
LuaThread(Globals globals)
Private constructor for main thread only
|
LuaThread(Globals globals,
LuaValue func)
Create a LuaThread around a function and environment
|
| 限定符和类型 | 方法和说明 |
|---|---|
LuaThread |
checkthread()
|
LuaValue |
getmetatable()
Get the metatable for this
LuaValue
For LuaTable and LuaUserdata instances,
the metatable returned is this instance metatable. |
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.
|
String |
typename()
Get the String name of the type of this value.
|
add, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, band, band, bnot, bor, bor, buffer, bxor, bxor, call, call, call, call, call, callmt, checkboolean, checkclosure, checkdouble, checkfunction, checkglobals, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checktable, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eq_b, eq, eqmtcall, equals, error, get, get, get, getfenv, gettable, getuservalue, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, idiv, idiv, illegal, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isstring, istable, isuserdata, isuserdata, isvalidkey, jcall, jget, jset, len, lenerror, length, listOf, listOf, load, lt_b, lt_b, lt_b, lt, lt, lt, lteq_b, lteq_b, lteq_b, lteq, lteq, lteq, metatableOf, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq_b, neq, next, not, onInvoke, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optuserdata, optuserdata, optvalue, or, pow, pow, pow, powWith, powWith, presize, raweq, raweq, raweq, raweq, raweq, rawget, rawget, rawget, rawlen, rawset, rawset, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, set, set, setfenv, setmetatable, settable, setuservalue, shl, shl, shr, shr, strcmp, strcmp, strongvalue, strvalue, sub, sub, sub, subargs, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, tonumber, toshort, tostring, toString, touserdata, touserdata, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOfargcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, dealias, 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, typepublic 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 String[] STATUS_NAMES
public final LuaThread.State state
public static final int MAX_CALLSTACK
public DebugLib.CallStack callstack
public final Globals globals
public final LuaTable registry
public LuaValue errorfunc
public LuaThread(Globals globals)
public int type()
LuaValuetype 在类中 LuaValueLuaValue.TNIL,
LuaValue.TBOOLEAN,
LuaValue.TNUMBER,
LuaValue.TSTRING,
LuaValue.TTABLE,
LuaValue.TFUNCTION,
LuaValue.TUSERDATA,
LuaValue.TTHREADLuaValue.typename()public String typename()
LuaValuetypename 在类中 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 threadisthread 在类中 LuaValuethread, otherwise falseLuaValue.checkthread(),
LuaValue.optthread(LuaThread),
LuaValue.TTHREADpublic LuaThread optthread(LuaThread defval)
LuaValueLuaThreadoptthread 在类中 LuaValuedefval - LuaThread to return if this is nil or nonethis cast to LuaTable if a thread,
defval if nil or none,
throws LuaError if some other typeLuaValue.checkthread(),
LuaValue.isthread(),
LuaValue.TTHREADpublic LuaThread checkthread()
LuaValuecheckthread 在类中 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 在类中 LuaValueLuaBoolean.s_metatable,
LuaNumber.s_metatable,
LuaNil.s_metatable,
LuaFunction.s_metatable,
s_metatablepublic String getStatus()
public boolean isMainThread()
Copyright © 2020. All rights reserved.