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 class
A Slot whose value has been set to nil.static final class
static final class
static final class
static final 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
Nested 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 LuaTable
final LuaValue
Concatenate the contents of a table efficiently, usingBuffer
final LuaTable.Slot
final LuaValue
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
.final boolean
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
, and return java booleanfinal LuaValue
get
(int key) Get a value in a table including metatag processing usingLuaValue.INDEX
.final LuaValue
Get a value in a table including metatag processing usingLuaValue.INDEX
.final int
final LuaValue
Get the metatable for thisLuaValue
static int
hashmod
(int hashCode, int mask) static int
hashpow2
(int hashCode, int mask) final void
Set a hashtable valuestatic int
Find the hashtable slot index to use.final Varargs
Get the next element after a particular key in the contiguous array part of a tablefinal void
Insert an element at a position in a list-tablefinal boolean
istable()
Check ifthis
is atable
final int
keyCount()
This may be deprecated in a future release.final LuaValue[]
keys()
This may be deprecated in a future release.final LuaValue
len()
Length operator: return lua length of object(#this)
including metatag processing as java intfinal int
length()
Length operator: return lua length of object(#this)
including metatag processing as java intfinal Varargs
Get the next element after a particular key in the tablefinal LuaTable
Check that optional argument is a table and return asLuaTable
final void
presize
(int narray) Preallocate the array part of a table to be a certain size,final void
presize
(int narray, int nhash) final LuaValue
rawget
(int key) Get a value in a table without metatag processing.final LuaValue
Get a value in a table without metatag processing.final 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
remove
(int pos) Remove the element at a position in a list-tablevoid
Set a value in a table without metatag processing usingLuaValue.NEWINDEX
.final void
caller must ensure key is not nilsetmetatable
(LuaValue metatable) Set the metatable for thisLuaValue
final void
Sort the table using a comparator.final int
type()
Get the enumeration value for the type of this value.final String
typename()
Get the String name of the type of this value.final Varargs
unpack()
Unpack all the elements of this tablefinal Varargs
unpack
(int i) Unpack all the elements of this table from element ifinal Varargs
unpack
(int i, int j) Unpack the elements from i to j inclusiveboolean
boolean
void
Methods 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, varargsOf
Methods 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:
write
in interfaceKryoSerializable
-
read
- Specified by:
read
in interfaceKryoSerializable
-
getHashEntries
public final int getHashEntries()- Returns:
- number of hash entries
-
type
public final 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 final 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 final 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 final 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
-
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
-
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 final 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 final 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
- 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
- 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 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: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
-