Class LuaTable
- All Implemented Interfaces:
KryoSerializable
- Direct Known Subclasses:
ClassTreeLuaTable,GlobalCLuaTable,Globals,ReadOnlyLuaTable
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)- plus overloads such as
LuaValue.get(String),get(int), and so on
To 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 parts
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA Slot whose value has been set to nil.static final classstatic final classstatic final classstatic final classEntry class used with numeric values, but only when the key is not an integer.static interfaceRepresents a slot in the hash table.Nested classes/interfaces inherited from class com.prineside.luaj.LuaValue
LuaValue.NillableSerializer, LuaValue.NoneNested classes/interfaces inherited from class com.prineside.luaj.Varargs
Varargs.ArrayVarargs -
Field Summary
FieldsFields inherited from class com.prineside.luaj.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, IPAIRS, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILLABLE_SERIALIZER, NILS, NONE, NOVALS, ONE, PAIRS, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal LuaTablefinal LuaValueConcatenate the contents of a table efficiently, usingBufferfinal LuaTable.Slotfinal LuaValueEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ.final booleanEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ, and return java booleanfinal LuaValueget(int key) Get a value in a table including metatag processing usingLuaValue.INDEX.final LuaValueGet a value in a table including metatag processing usingLuaValue.INDEX.final intfinal LuaValueGet the metatable for thisLuaValuestatic inthashmod(int hashCode, int mask) static inthashpow2(int hashCode, int mask) final voidSet a hashtable valuestatic intFind the hashtable slot index to use.final VarargsGet the next element after a particular key in the contiguous array part of a tablefinal voidInsert an element at a position in a list-tablefinal booleanistable()Check ifthisis atablefinal intkeyCount()This may be deprecated in a future release.final LuaValue[]keys()This may be deprecated in a future release.final LuaValuelen()Length operator: return lua length of object(#this)including metatag processing as java intfinal intlength()Length operator: return lua length of object(#this)including metatag processing as java intfinal VarargsGet the next element after a particular key in the tablefinal LuaTableCheck that optional argument is a table and return asLuaTablefinal voidpresize(int narray) Preallocate the array part of a table to be a certain size,final voidpresize(int narray, int nhash) final LuaValuerawget(int key) Get a value in a table without metatag processing.final LuaValueGet a value in a table without metatag processing.final intrawlen()Get raw length of table or string without metatag processing.voidSet a value in a table without metatag processing.voidcaller must ensure key is not nilvoidremove(int pos) Remove the element at a position in a list-tablevoidSet a value in a table without metatag processing usingLuaValue.NEWINDEX.final voidcaller must ensure key is not nilsetmetatable(LuaValue metatable) Set the metatable for thisLuaValuefinal voidSort the table using a comparator.final inttype()Get the enumeration value for the type of this value.final Stringtypename()Get the String name of the type of this value.final Varargsunpack()Unpack all the elements of this tablefinal Varargsunpack(int i) Unpack all the elements of this table from element ifinal Varargsunpack(int i, int j) Unpack the elements from i to j inclusivebooleanbooleanvoidMethods inherited from class com.prineside.luaj.LuaValue
add, add, add, and, arg, arg1, argerror, assert_, buffer, call, call, call, call, call, cBool, cDouble, cFloat, checkboolean, checkclosure, checkdouble, checkfunction, checkglobals, checkint, checkjstring, checklong, checknotnil, checknumber, checknumber, checkstring, checkuserdata, checkuserdata, cInt, cNcDouble, cNcFloat, cNcInt, cObject, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, cRegObject, div, div, div, divInto, eqmtcall, equals, error, get, gt, gt, gt, gt_b, gt_b, gt_b, gteq, gteq, gteq, gteq_b, gteq_b, gteq_b, initupvalue1, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isRegObject, isstring, isuserdata, isuserdata, isvalidkey, listOf, listOf, load, lt, lt, lt, lt_b, lt_b, lt_b, lteq, lteq, lteq, lteq_b, lteq_b, lteq_b, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq, neq_b, not, onInvoke, optboolean, optclosure, optdouble, optfunction, optint, optjstring, optlong, optnumber, optstring, 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, 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, userdataOf, userdataOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOfMethods inherited from class com.prineside.luaj.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkuserdata, checkuserdata, checkvalue, dealias, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optjstring, optlong, optnumber, optstring, opttable, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type
-
Field Details
-
CLASS_COMPARATOR
-
-
Constructor Details
-
LuaTable
public LuaTable()Construct empty table -
LuaTable
public LuaTable(int narray, int nhash) Construct table with preset capacity.- Parameters:
narray- capacity of array partnhash- capacity of hash part
-
LuaTable
Construct table with named and unnamed parts.- Parameters:
named- Named elements in orderkey-a, value-a, key-b, value-b, ...unnamed- Unnamed elements in ordervalue-1, value-2, ...lastarg- Additional unnamed values beyondunnamed.length
-
LuaTable
Construct table of unnamed elements.- Parameters:
varargs- Unnamed elements in ordervalue-1, value-2, ...
-
LuaTable
Construct table of unnamed elements.- Parameters:
varargs- Unnamed elements in ordervalue-1, value-2, ...firstarg- the index in varargs of the first argument to include in the table
-
-
Method Details
-
write
- Specified by:
writein interfaceKryoSerializable
-
read
- Specified by:
readin interfaceKryoSerializable
-
getHashEntries
public final int getHashEntries()- Returns:
- number of hash entries
-
type
public final int type()Description copied from class:LuaValueGet the enumeration value for the type of this value.- Specified by:
typein classLuaValue- Returns:
- value for this type, one of
LuaValue.TNIL,LuaValue.TBOOLEAN,LuaValue.TNUMBER,LuaValue.TSTRING,LuaValue.TTABLE,LuaValue.TFUNCTION,LuaValue.TUSERDATA,LuaValue.TTHREAD - See Also:
-
typename
Description copied from class:LuaValueGet the String name of the type of this value.- Specified by:
typenamein classLuaValue- Returns:
- name from type name list
LuaValue.TYPE_NAMEScorresponding to the type of this value: "nil", "boolean", "number", "string", "table", "function", "userdata", "thread" - See Also:
-
istable
public final boolean istable()Description copied from class:LuaValueCheck ifthisis atable -
checktable
Description copied from class:LuaValue- Overrides:
checktablein classLuaValue- Returns:
thisif it is aLuaTable- See Also:
-
opttable
Description copied from class:LuaValueCheck that optional argument is a table and return asLuaTable -
presize
public final void presize(int narray) Description copied from class:LuaValuePreallocate the array part of a table to be a certain size,Primarily used internally in response to a SETLIST bytecode.
-
presize
public final void presize(int narray, int nhash) -
getmetatable
Description copied from class:LuaValueGet the metatable for thisLuaValueFor
LuaTableandLuaUserdatainstances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.- Overrides:
getmetatablein classLuaValue- Returns:
- metatable, or null if it there is none
-
setmetatable
Description copied from class:LuaValueSet the metatable for thisLuaValueFor
LuaTableandLuaUserdatainstances, the metatable is per instance. For all other types, there is one metatable per type that can be set directly from java- Overrides:
setmetatablein classLuaValue- Parameters:
metatable-LuaValueinstance to serve as the metatable, or null to reset it.- Returns:
thisto allow chaining of Java function calls
-
get
Description copied from class:LuaValueGet a value in a table including metatag processing usingLuaValue.INDEX.- Overrides:
getin classLuaValue- Parameters:
key- the key to look up- Returns:
LuaValuefor that key, orLuaValue.NILif not found- See Also:
-
get
Description copied from class:LuaValueGet a value in a table including metatag processing usingLuaValue.INDEX.- Overrides:
getin classLuaValue- Parameters:
key- the key to look up, must not beLuaValue.NILor null- Returns:
LuaValuefor that key, orLuaValue.NILif not found and no metatag- See Also:
-
rawget
Description copied from class:LuaValueGet a value in a table without metatag processing.- Overrides:
rawgetin classLuaValue- Parameters:
key- the key to look up- Returns:
LuaValuefor that key, orLuaValue.NILif not found
-
rawget
Description copied from class:LuaValueGet a value in a table without metatag processing.- Overrides:
rawgetin classLuaValue- Parameters:
key- the key to look up, must not beLuaValue.NILor null- Returns:
LuaValuefor that key, orLuaValue.NILif not found
-
set
Description copied from class:LuaValueSet a value in a table without metatag processing usingLuaValue.NEWINDEX.- Overrides:
setin classLuaValue- Parameters:
key- the key to usevalue- the value to use, can beLuaValue.NIL, must not be null
-
set
caller must ensure key is not nil- Overrides:
setin classLuaValue- Parameters:
key- the key to use, must not beLuaValue.NILor nullvalue- the value to use, can beLuaValue.NIL, must not be null
-
rawset
Description copied from class:LuaValueSet a value in a table without metatag processing.- Overrides:
rawsetin classLuaValue- Parameters:
key- the key to usevalue- the value to use, can beLuaValue.NIL, must not be null
-
rawset
caller must ensure key is not nil- Overrides:
rawsetin classLuaValue- Parameters:
key- the key to use, must not beLuaValue.NILor nullvalue- the value to use, can beLuaValue.NIL, must not be null
-
remove
Remove the element at a position in a list-table- Parameters:
pos- the position to remove- Returns:
- The removed item, or
LuaValue.NONEif not removed
-
insert
Insert an element at a position in a list-table- Parameters:
pos- the position to removevalue- The value to insert
-
concat
Concatenate the contents of a table efficiently, usingBuffer -
length
public final int length()Description copied from class:LuaValueLength operator: return lua length of object(#this)including metatag processing as java int- Overrides:
lengthin classLuaValue- Returns:
- length as defined by the lua # operator
or metatag processing result converted to java int using
LuaValue.toint()
-
len
Description copied from class:LuaValueLength operator: return lua length of object(#this)including metatag processing as java int -
rawlen
public final int rawlen()Description copied from class:LuaValueGet raw length of table or string without metatag processing. -
next
Get the next element after a particular key in the table- Overrides:
nextin classLuaValue- Parameters:
key- value identifying a key to start from, orLuaValue.NILto start at the beginning- Returns:
- key,value or nil
- See Also:
-
inext
Get the next element after a particular key in the contiguous array part of a table- Overrides:
inextin classLuaValue- Parameters:
key- value identifying a key to start from, orLuaValue.NILto start at the beginning- Returns:
- key,value or none
- See Also:
-
hashset
Set a hashtable value- Parameters:
key- key to setvalue- value to set
-
hashpow2
public static int hashpow2(int hashCode, int mask) -
hashmod
public static int hashmod(int hashCode, int mask) -
hashSlot
Find the hashtable slot index to use.- Parameters:
key- the key to look forhashMask- N-1 where N is the number of hash slots (must be power of 2)- Returns:
- the slot index
-
entry
-
sort
Sort the table using a comparator.- Parameters:
comparator-LuaValueto be called to compare elements.
-
keyCount
public final int keyCount()This may be deprecated in a future release. It is recommended to count via iteration over next() instead- Returns:
- count of keys in the table
-
keys
This may be deprecated in a future release. It is recommended to use next() instead- Returns:
- array of keys in the table
-
eq
Description copied from class:LuaValueEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ.- Overrides:
eqin classLuaValue- Parameters:
val- The value to compare with.- Returns:
LuaValue.TRUEif values are comparable and(this == rhs),LuaValue.FALSEif comparable but not equal,LuaValueif metatag processing occurs.- See Also:
-
eq_b
Description copied from class:LuaValueEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ, and return java boolean -
unpack
Unpack all the elements of this table -
unpack
Unpack all the elements of this table from element i -
unpack
Unpack the elements from i to j inclusive -
useWeakKeys
public boolean useWeakKeys() -
useWeakValues
public boolean useWeakValues() -
toLuaValue
-
wrap
-
arrayget
-