public class LuaTable extends LuaValue
LuaValue for representing lua tables.
Almost all API's implemented in LuaTable are defined and documented in LuaValue.
If a table is needed, the one of the type-checking functions can be used such as
istable(),
checktable(), or
opttable(LuaTable)
The main table operations are defined on LuaValue
for getting and setting values with and without metatag processing:
get(LuaValue)set(LuaValue, LuaValue)rawget(LuaValue)rawset(LuaValue, LuaValue)LuaValue.get(String), get(int), and so onTo iterate over key-value pairs from Java, use
LuaValue k = LuaValue.NIL;
while ( true ) {
Varargs n = table.next(k);
if ( (k = n.arg1()).isnil() )
break;
LuaValue v = n.arg(2)
process( k, v )
}
As with other types, LuaTable instances should be constructed via one of the table constructor
methods on LuaValue:
LuaValue.tableOf() empty tableLuaValue.tableOf(int, int) table with capacityLuaValue.listOf(LuaValue[]) initialize array partLuaValue.listOf(LuaValue[], Varargs) initialize array partLuaValue.tableOf(LuaValue[]) initialize named hash partLuaValue.tableOf(Varargs, int) initialize named hash partLuaValue.tableOf(LuaValue[], LuaValue[]) initialize array and named partsLuaValue.tableOf(LuaValue[], LuaValue[], Varargs) initialize array and named partsLuaValue| 限定符和类型 | 字段和说明 |
|---|---|
protected LuaValue[] |
array
the array values
|
protected org.luaj.vm2.LuaTable.Slot[] |
hash
the hash part
|
protected int |
hashEntries
the number of hash entries
|
protected org.luaj.vm2.Metatable |
m_metatable
metatable for this table, or null
|
protected boolean |
mConst |
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| 构造器和说明 |
|---|
LuaTable()
Construct empty table
|
LuaTable(int narray,
int nhash)
Construct table with preset capacity.
|
LuaTable(LuaTable t) |
LuaTable(LuaValue[] named,
LuaValue[] unnamed,
Varargs lastarg)
Construct table with named and unnamed parts.
|
LuaTable(Varargs varargs)
Construct table of unnamed elements.
|
LuaTable(Varargs varargs,
int firstarg)
Construct table of unnamed elements.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
_const() |
LuaValue |
arrayget(LuaValue[] array,
int index)
Returns the value at the given index in the array, or null if it is a weak reference that
has been dropped.
|
LuaTable |
checktable()
|
void |
clear() |
LuaTable |
clone() |
LuaValue |
concat(LuaString sep,
int i,
int j)
Concatenate the contents of a table efficiently, using
Buffer |
protected static org.luaj.vm2.LuaTable.Entry |
defaultEntry(LuaValue key,
LuaValue value) |
org.luaj.vm2.LuaTable.Slot |
entry(LuaValue key,
LuaValue value)
Return an instance of Slot appropriate for the given key and value.
|
boolean |
eq_b(LuaValue val)
Equals: Perform equality comparison with another value
including metatag processing using
LuaValue.EQ,
and return java boolean |
LuaValue |
eq(LuaValue val)
Equals: Perform equality comparison with another value
including metatag processing using
LuaValue.EQ. |
LuaValue |
find(LuaValue v,
LuaValue k) |
LuaValue |
get(int key)
Get a value in a table including metatag processing using
LuaValue.INDEX. |
LuaValue |
get(LuaValue key)
Get a value in a table including metatag processing using
LuaValue.INDEX. |
protected int |
getArrayLength()
Get the length of the array part of the table.
|
protected int |
getHashLength()
Get the length of the hash part of the table.
|
LuaValue |
getmetatable()
Get the metatable for this
LuaValue
For LuaTable and LuaUserdata instances,
the metatable returned is this instance metatable. |
protected LuaValue |
hashget(LuaValue key) |
static int |
hashmod(int hashCode,
int mask) |
static int |
hashpow2(int hashCode,
int mask) |
void |
hashset(LuaValue key,
LuaValue value)
Set a hashtable value
|
static int |
hashSlot(LuaValue key,
int hashMask)
Find the hashtable slot index to use.
|
Varargs |
inext(LuaValue key)
Get the next element after a particular key in the
contiguous array part of a table
|
void |
insert(int pos,
LuaValue value)
Insert an element at a position in a list-table
|
protected static boolean |
isLargeKey(LuaValue key) |
boolean |
istable()
Check if
this is a table |
int |
keyCount()
This may be deprecated in a future release.
|
LuaValue[] |
keys()
This may be deprecated in a future release.
|
LuaValue |
len()
Length operator: return lua length of object
(#this) including metatag processing as java int |
int |
length()
Length operator: return lua length of object
(#this) including metatag processing as java int |
Varargs |
next(LuaValue key)
Get the next element after a particular key in the table
|
LuaTable |
opttable(LuaTable defval)
Check that optional argument is a table and return as
LuaTable |
void |
presize(int narray)
Preallocate the array part of a table to be a certain size,
Primarily used internally in response to a SETLIST bytecode.
|
void |
presize(int narray,
int nhash) |
LuaValue |
rawget(int key)
Get a value in a table without metatag processing.
|
LuaValue |
rawget(LuaValue key)
Get a value in a table without metatag processing.
|
int |
rawlen()
Get raw length of table or string without metatag processing.
|
void |
rawset(int key,
LuaValue value)
Set a value in a table without metatag processing.
|
void |
rawset(LuaValue key,
LuaValue value)
caller must ensure key is not nil
|
LuaValue |
remove(int pos)
Remove the element at a position in a list-table
|
void |
set(int key,
LuaValue value)
Set a value in a table without metatag processing using
LuaValue.NEWINDEX. |
void |
set(LuaValue key,
LuaValue value)
caller must ensure key is not nil
|
LuaValue |
setmetatable(LuaValue metatable)
Set the metatable for this
LuaValue
For LuaTable and LuaUserdata instances, the metatable is per instance. |
LuaValue |
size() |
void |
sort(LuaValue comparator)
Sort the table using a comparator.
|
LuaValue |
toLuaValue()
Return this metatable as a LuaValue.
|
int |
type()
Get the enumeration value for the type of this value.
|
String |
typename()
Get the String name of the type of this value.
|
Varargs |
unpack()
Unpack all the elements of this table
|
Varargs |
unpack(int i)
Unpack all the elements of this table from element i
|
Varargs |
unpack(int i,
int j)
Unpack the elements from i to j inclusive
|
boolean |
useWeakKeys()
Return whether or not this table's keys are weak.
|
boolean |
useWeakValues()
Return whether or not this table's values are weak.
|
LuaValue |
wrap(LuaValue value)
Returns the given value wrapped in a weak reference if appropriate.
|
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, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eqmtcall, equals, error, 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, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isstring, isthread, isuserdata, isuserdata, isvalidkey, jcall, jget, jset, lenerror, 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, not, onInvoke, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, optthread, optuserdata, optuserdata, optvalue, or, pow, pow, pow, powWith, powWith, raweq, raweq, raweq, raweq, raweq, rawget, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, setfenv, 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, typeprotected LuaValue[] array
protected org.luaj.vm2.LuaTable.Slot[] hash
protected int hashEntries
protected org.luaj.vm2.Metatable m_metatable
protected boolean mConst
public LuaTable()
public LuaTable(LuaTable t)
public LuaTable(int narray,
int nhash)
narray - capacity of array partnhash - capacity of hash partpublic LuaTable(LuaValue[] named, LuaValue[] unnamed, Varargs lastarg)
named - Named elements in order key-a, value-a, key-b, value-b, ... unnamed - Unnamed elements in order value-1, value-2, ... lastarg - Additional unnamed values beyond unnamed.lengthpublic LuaTable(Varargs varargs)
varargs - Unnamed elements in order value-1, value-2, ... public LuaTable(Varargs varargs, int firstarg)
varargs - Unnamed elements in order value-1, value-2, ... firstarg - the index in varargs of the first argument to include in the tablepublic void clear()
public void _const()
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 istable()
LuaValuethis is a tableistable 在类中 LuaValuetable, otherwise falseLuaValue.checktable(),
LuaValue.opttable(LuaTable),
LuaValue.TTABLEpublic LuaTable checktable()
LuaValuechecktable 在类中 LuaValuethis if it is a LuaTableLuaValue.istable(),
LuaValue.opttable(LuaTable),
LuaValue.TTABLEpublic LuaTable opttable(LuaTable defval)
LuaValueLuaTableopttable 在类中 LuaValuedefval - LuaTable to return if this is nil or nonethis cast to LuaTable if a table,
defval if nil or none,
throws LuaError if some other typeLuaValue.checktable(),
LuaValue.istable(),
LuaValue.TTABLEpublic void presize(int narray)
LuaValuePrimarily used internally in response to a SETLIST bytecode.
public void presize(int narray,
int nhash)
protected int getArrayLength()
protected int getHashLength()
public 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,
LuaThread.s_metatablepublic LuaValue setmetatable(LuaValue metatable)
LuaValueLuaValue
For LuaTable and LuaUserdata instances, the metatable is per instance.
For all other types, there is one metatable per type that can be set directly from java
setmetatable 在类中 LuaValuemetatable - LuaValue instance to serve as the metatable, or null to reset it.this to allow chaining of Java function callsLuaBoolean.s_metatable,
LuaNumber.s_metatable,
LuaNil.s_metatable,
LuaFunction.s_metatable,
LuaThread.s_metatablepublic LuaValue get(int key)
LuaValueLuaValue.INDEX.get 在类中 LuaValuekey - the key to look upLuaValue for that key, or LuaValue.NIL if not foundLuaValue.get(LuaValue),
LuaValue.rawget(int)public LuaValue get(LuaValue key)
LuaValueLuaValue.INDEX.get 在类中 LuaValuekey - the key to look up, must not be LuaValue.NIL or nullLuaValue for that key, or LuaValue.NIL if not found and no metatagLuaValue.get(int),
LuaValue.get(String),
LuaValue.rawget(LuaValue)public LuaValue rawget(int key)
LuaValuerawget 在类中 LuaValuekey - the key to look upLuaValue for that key, or LuaValue.NIL if not foundpublic LuaValue rawget(LuaValue key)
LuaValuerawget 在类中 LuaValuekey - the key to look up, must not be LuaValue.NIL or nullLuaValue for that key, or LuaValue.NIL if not foundpublic void set(int key,
LuaValue value)
LuaValueLuaValue.NEWINDEX.set 在类中 LuaValuekey - the key to usevalue - the value to use, can be LuaValue.NIL, must not be nullpublic void set(LuaValue key, LuaValue value)
set 在类中 LuaValuekey - the key to use, must not be LuaValue.NIL or nullvalue - the value to use, can be LuaValue.NIL, must not be nullpublic void rawset(int key,
LuaValue value)
LuaValuerawset 在类中 LuaValuekey - the key to usevalue - the value to use, can be LuaValue.NIL, must not be nullpublic void rawset(LuaValue key, LuaValue value)
rawset 在类中 LuaValuekey - the key to use, must not be LuaValue.NIL or nullvalue - the value to use, can be LuaValue.NIL, must not be nullpublic LuaValue remove(int pos)
pos - the position to removeLuaValue.NONE if not removedpublic void insert(int pos,
LuaValue value)
pos - the position to removevalue - The value to insertpublic LuaValue concat(LuaString sep, int i, int j)
Bufferpublic int length()
LuaValue(#this) including metatag processing as java intlength 在类中 LuaValueLuaValue.toint()public LuaValue len()
LuaValue(#this) including metatag processing as java intpublic int rawlen()
LuaValuepublic Varargs next(LuaValue key)
next 在类中 LuaValuekey - LuaInteger value identifying a key to start from,
or LuaValue.NIL to start at the beginningLuaTable,
LuaValue.inext(LuaValue),
LuaValue.valueOf(int),
Varargs.arg1(),
Varargs.arg(int),
LuaValue.isnil()public Varargs inext(LuaValue key)
inext 在类中 LuaValuekey - LuaInteger value identifying a key to start from,
or LuaValue.NIL to start at the beginningLuaTable,
LuaValue.next(LuaValue),
LuaValue.valueOf(int),
Varargs.arg1(),
Varargs.arg(int),
LuaValue.isnil()public void hashset(LuaValue key, LuaValue value)
key - key to setvalue - value to setpublic static int hashpow2(int hashCode,
int mask)
public static int hashmod(int hashCode,
int mask)
public static int hashSlot(LuaValue key, int hashMask)
key - the key to look forhashMask - N-1 where N is the number of hash slots (must be power of 2)public org.luaj.vm2.LuaTable.Slot entry(LuaValue key, LuaValue value)
protected static boolean isLargeKey(LuaValue key)
protected static org.luaj.vm2.LuaTable.Entry defaultEntry(LuaValue key, LuaValue value)
public void sort(LuaValue comparator)
comparator - LuaValue to be called to compare elements.public int keyCount()
public LuaValue[] keys()
public LuaValue eq(LuaValue val)
LuaValueLuaValue.EQ.eq 在类中 LuaValueval - The value to compare with.LuaValue.TRUE if values are comparable and (this == rhs),
LuaValue.FALSE if comparable but not equal,
LuaValue if metatag processing occurs.LuaValue.eq_b(LuaValue),
LuaValue.raweq(LuaValue),
LuaValue.neq(LuaValue),
LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue),
LuaValue.EQpublic boolean eq_b(LuaValue val)
LuaValueLuaValue.EQ,
and return java booleaneq_b 在类中 LuaValueval - The value to compare with.(this == rhs),
false if comparable but not equal,
result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue),
LuaValue.raweq(LuaValue),
LuaValue.neq_b(LuaValue),
LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue),
LuaValue.EQpublic Varargs unpack()
public Varargs unpack(int i)
public Varargs unpack(int i, int j)
public LuaValue size()
public boolean useWeakKeys()
public boolean useWeakValues()
public LuaValue toLuaValue()
public LuaValue wrap(LuaValue value)
Copyright © 2020. All rights reserved.