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 class
A Slot whose value has been set to nil.static class
static class
static class
static class
Entry class used with numeric values, but only when the key is not an integer.static interface
Represents 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, usingBuffer
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
.boolean
Equals: 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 thisLuaValue
static int
hashmod
(int hashCode, int mask) static int
hashpow2
(int hashCode, int mask) void
Set a hashtable valuestatic int
Find the hashtable slot index to use.Get the next element after a particular key in the contiguous array part of a tablevoid
Insert an element at a position in a list-tableboolean
istable()
Check ifthis
is atable
int
keyCount()
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 intint
length()
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 asLuaTable
void
presize
(int narray) Preallocate the array part of a table to be a certain size,void
presize
(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.int
rawlen()
Get raw length of table or string without metatag processing.void
Set a value in a table without metatag processing.void
caller must ensure key is not nilvoid
read
(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) remove
(int pos) Remove the element at a position in a list-tablevoid
Set a value in a table without metatag processing usingLuaValue.NEWINDEX
.void
caller must ensure key is not nilsetmetatable
(LuaValue metatable) Set the metatable for thisLuaValue
void
Sort the table using a comparator.int
type()
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 inclusiveboolean
boolean
void
write
(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, varargsOf
Methods 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:
write
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) - Specified by:
read
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
type
public int type()Description copied from class:LuaValue
Get the enumeration value for the type of this value.- Specified by:
type
in 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:LuaValue
Get the String name of the type of this value.- Specified by:
typename
in classLuaValue
- Returns:
- name from type name list
LuaValue.TYPE_NAMES
corresponding to the type of this value: "nil", "boolean", "number", "string", "table", "function", "userdata", "thread" - See Also:
-
istable
public boolean istable()Description copied from class:LuaValue
Check ifthis
is atable
-
checktable
Description copied from class:LuaValue
- Overrides:
checktable
in classLuaValue
- Returns:
this
if it is aLuaTable
- See Also:
-
opttable
Description copied from class:LuaValue
Check that optional argument is a table and return asLuaTable
-
presize
public void presize(int narray) Description copied from class:LuaValue
Preallocate 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:LuaValue
Get the metatable for thisLuaValue
For
LuaTable
andLuaUserdata
instances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.- Overrides:
getmetatable
in classLuaValue
- Returns:
- metatable, or null if it there is none
- See Also:
-
setmetatable
Description copied from class:LuaValue
Set the metatable for thisLuaValue
For
LuaTable
andLuaUserdata
instances, the metatable is per instance. For all other types, there is one metatable per type that can be set directly from java- Overrides:
setmetatable
in classLuaValue
- Parameters:
metatable
-LuaValue
instance to serve as the metatable, or null to reset it.- Returns:
this
to allow chaining of Java function calls- See Also:
-
get
Description copied from class:LuaValue
Get a value in a table including metatag processing usingLuaValue.INDEX
.- Overrides:
get
in classLuaValue
- Parameters:
key
- the key to look up- Returns:
LuaValue
for that key, orLuaValue.NIL
if not found- See Also:
-
get
Description copied from class:LuaValue
Get a value in a table including metatag processing usingLuaValue.INDEX
.- Overrides:
get
in classLuaValue
- Parameters:
key
- the key to look up, must not beLuaValue.NIL
or null- Returns:
LuaValue
for that key, orLuaValue.NIL
if not found and no metatag- See Also:
-
rawget
Description copied from class:LuaValue
Get a value in a table without metatag processing.- Overrides:
rawget
in classLuaValue
- Parameters:
key
- the key to look up- Returns:
LuaValue
for that key, orLuaValue.NIL
if not found
-
rawget
Description copied from class:LuaValue
Get a value in a table without metatag processing.- Overrides:
rawget
in classLuaValue
- Parameters:
key
- the key to look up, must not beLuaValue.NIL
or null- Returns:
LuaValue
for that key, orLuaValue.NIL
if not found
-
set
Description copied from class:LuaValue
Set a value in a table without metatag processing usingLuaValue.NEWINDEX
.- Overrides:
set
in 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:
set
in classLuaValue
- Parameters:
key
- the key to use, must not beLuaValue.NIL
or nullvalue
- the value to use, can beLuaValue.NIL
, must not be null
-
rawset
Description copied from class:LuaValue
Set a value in a table without metatag processing.- Overrides:
rawset
in 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:
rawset
in classLuaValue
- Parameters:
key
- the key to use, must not beLuaValue.NIL
or 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.NONE
if 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:LuaValue
Length operator: return lua length of object(#this)
including metatag processing as java int- Overrides:
length
in 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:LuaValue
Length operator: return lua length of object(#this)
including metatag processing as java int -
rawlen
public int rawlen()Description copied from class:LuaValue
Get raw length of table or string without metatag processing. -
next
Get the next element after a particular key in the table- Overrides:
next
in classLuaValue
- Parameters:
key
-LuaInteger
value identifying a key to start from, orLuaValue.NIL
to 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:
inext
in classLuaValue
- Parameters:
key
-LuaInteger
value identifying a key to start from, orLuaValue.NIL
to 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
-LuaValue
to 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:LuaValue
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
.- Overrides:
eq
in classLuaValue
- Parameters:
val
- The value to compare with.- Returns:
LuaValue.TRUE
if values are comparable and(this == rhs)
,LuaValue.FALSE
if comparable but not equal,LuaValue
if metatag processing occurs.- See Also:
-
eq_b
Description copied from class:LuaValue
Equals: 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
-