Class LuaTable
- All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable
- Direct Known Subclasses:
Globals,ScriptManager.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 classA Slot whose value has been set to nil.static classstatic classstatic classstatic 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.None -
Field Summary
FieldsFields inherited from class com.prineside.luaj.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILLABLE_SERIALIZER, 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConcatenate the contents of a table efficiently, usingBufferEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ.booleanEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ, and return java booleanget(int key) Get a value in a table including metatag processing usingLuaValue.INDEX.Get a value in a table including metatag processing usingLuaValue.INDEX.Get the metatable for thisLuaValuestatic inthashmod(int hashCode, int mask) static inthashpow2(int hashCode, int mask) voidSet a hashtable valuestatic intFind the hashtable slot index to use.Get the next element after a particular key in the contiguous array part of a tablevoidInsert an element at a position in a list-tablebooleanistable()Check ifthisis atableintkeyCount()This may be deprecated in a future release.LuaValue[]keys()This may be deprecated in a future release.len()Length operator: return lua length of object(#this)including metatag processing as java intintlength()Length operator: return lua length of object(#this)including metatag processing as java intGet the next element after a particular key in the tableCheck that optional argument is a table and return asLuaTablevoidpresize(int narray) Preallocate the array part of a table to be a certain size,voidpresize(int narray, int nhash) rawget(int key) Get a value in a table without metatag processing.Get a value in a table without metatag processing.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 nilvoidread(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) remove(int pos) Remove the element at a position in a list-tablevoidSet a value in a table without metatag processing usingLuaValue.NEWINDEX.voidcaller must ensure key is not nilsetmetatable(LuaValue metatable) Set the metatable for thisLuaValuevoidSort the table using a comparator.inttype()Get the enumeration value for the type of this value.typename()Get the String name of the type of this value.unpack()Unpack all the elements of this tableunpack(int i) Unpack all the elements of this table from element iunpack(int i, int j) Unpack the elements from i to j inclusivebooleanbooleanvoidwrite(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) Methods inherited from class com.prineside.luaj.LuaValue
add, add, add, and, arg, arg1, argerror, assert_, buffer, cachedDouble, cachedInt, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, call, call, call, call, call, checkboolean, checkclosure, checkdouble, checkfunction, checkglobals, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checknumber, checkstring, checkthread, checkuserdata, checkuserdata, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, 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, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isstring, isthread, 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, 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, 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, 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, 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
public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) - Specified by:
writein interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) - Specified by:
readin interfacecom.esotericsoftware.kryo.KryoSerializable
-
type
public 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 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 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 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
- See Also:
-
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- 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- 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 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 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-LuaIntegervalue 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-LuaIntegervalue 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 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
-