|
||||||||||
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 a call to #setGlobals(LuaValue)
at some point during globals initialization.
See BaseLib
for additional documentation and example code.
The utility classes JsePlatform
and JmePlatform
see to it that this initialization is done properly.
For this reason it is highly recommended to use one of these classes
when initializing globals.
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.
LuaValue
,
JsePlatform
,
JmePlatform
,
CoroutineLib
Nested Class Summary | |
---|---|
static class |
LuaThread.State
|
Field Summary | |
---|---|
int |
bytecodes
|
java.lang.Object |
callstack
Thread-local used by DebugLib to store debugging state. |
static int |
coroutine_count
|
static int |
GC_INTERVAL
Interval to check for LuaThread dereferencing. |
Globals |
globals
|
boolean |
hookcall
|
int |
hookcount
|
LuaValue |
hookfunc
|
boolean |
hookline
|
boolean |
hookrtrn
|
boolean |
inhook
|
int |
lastline
|
static int |
MAX_CALLSTACK
|
static LuaValue |
s_metatable
|
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
|
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 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 static int GC_INTERVAL
public java.lang.Object callstack
public final Globals globals
public LuaValue hookfunc
public boolean hookline
public boolean hookcall
public boolean hookrtrn
public int hookcount
public boolean inhook
public int lastline
public int bytecodes
Constructor Detail |
---|
public LuaThread(Globals globals)
public LuaThread(Globals globals, LuaValue func)
func
- The function to executeMethod Detail |
---|
public int type()
LuaValue
type
in class LuaValue
TNIL
,
TBOOLEAN
,
TNUMBER
,
TSTRING
,
TTABLE
,
TFUNCTION
,
TUSERDATA
,
TTHREAD
LuaValue.typename()
public java.lang.String typename()
LuaValue
typename
in class LuaValue
LuaValue.TYPE_NAMES
corresponding to the type of this value:
"nil", "boolean", "number", "string",
"table", "function", "userdata", "thread"LuaValue.type()
public boolean isthread()
LuaValue
this
is a thread
isthread
in class LuaValue
thread
, otherwise falseLuaValue.checkthread()
,
LuaValue.optthread(LuaThread)
,
LuaValue.TTHREAD
public LuaThread optthread(LuaThread defval)
LuaValue
LuaThread
optthread
in class LuaValue
defval
- 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.TTHREAD
public LuaThread checkthread()
LuaValue
LuaThread
, or throw LuaError
if it is not
checkthread
in class LuaValue
this
if it is a LuaThread
LuaValue.isthread()
,
LuaValue.optthread(LuaThread)
,
LuaValue.TTHREAD
public LuaValue getmetatable()
LuaValue
LuaValue
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 LuaValue
LuaBoolean.s_metatable
,
LuaNumber.s_metatable
,
LuaNil.s_metatable
,
LuaFunction.s_metatable
,
s_metatable
public 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 |