|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.luaj.vm2.Varargs
org.luaj.vm2.LuaValue
org.luaj.vm2.LuaTable
public class LuaTable
Subclass of 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 parts
LuaValue| Field Summary | |
|---|---|
protected LuaValue[] |
array
the array values |
protected int |
hashEntries
the number of hash entries |
protected LuaValue[] |
hashKeys
the hash keys |
protected LuaValue[] |
hashValues
the hash values |
protected LuaValue |
m_metatable
metatable for this table, or null |
| Fields inherited from class org.luaj.vm2.LuaValue |
|---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, 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 | |
|---|---|
LuaTable()
Construct empty table |
|
LuaTable(int narray,
int nhash)
Construct table with preset capacity. |
|
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. |
|
| Method Summary | |
|---|---|
protected LuaTable |
changemode(boolean weakkeys,
boolean weakvalues)
Change the mode of a table |
LuaTable |
checktable()
Check that this is a LuaTable, or throw LuaError if it is not |
LuaValue |
concat(LuaString sep,
int i,
int j)
Concatenate the contents of a table efficiently, using Buffer |
boolean |
eq_b(LuaValue val)
Equals: Perform equality comparison with another value including metatag processing using EQ,
and return java boolean |
LuaValue |
eq(LuaValue val)
Equals: Perform equality comparison with another value including metatag processing using EQ. |
LuaValue |
foreach(LuaValue func)
Call the supplied function once for each key-value pair |
LuaValue |
foreachi(LuaValue func)
Call the supplied function once for each key-value pair in the contiguous array part |
LuaValue |
get(int key)
Get a value in a table including metatag processing using INDEX. |
LuaValue |
get(LuaValue key)
Get a value in a table including metatag processing using 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 |
LuaValue |
getn()
Implementation of lua 5.0 getn() function. |
protected void |
hashClearSlot(int i)
Clear a particular slot in the table |
int |
hashFindSlot(LuaValue key)
Find the hashtable slot to use |
protected LuaValue |
hashget(LuaValue key)
|
void |
hashset(LuaValue key,
LuaValue value)
Set a hashtable value |
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 |
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 |
int |
maxn()
Return table.maxn() as defined by lua 5.0. |
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, |
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. |
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 NEWINDEX. |
void |
set(LuaValue key,
LuaValue value)
caller must ensure key is not nil |
LuaValue |
setmetatable(LuaValue metatable)
Set the metatable for this LuaValue |
void |
sort(LuaValue comparator)
Sort the table using a comparator. |
int |
type()
Get the enumeration value for the type of this value. |
java.lang.String |
typename()
Get the String name of the type of this value. |
| Methods inherited from class org.luaj.vm2.Varargs |
|---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, 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, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected LuaValue[] array
protected LuaValue[] hashKeys
protected LuaValue[] hashValues
protected int hashEntries
protected LuaValue m_metatable
| Constructor Detail |
|---|
public LuaTable()
public LuaTable(int narray,
int nhash)
narray - capacity of array partnhash - capacity of hash part
public 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 table| Method Detail |
|---|
public int type()
LuaValue
type in class LuaValueTNIL,
TBOOLEAN,
TNUMBER,
TSTRING,
TTABLE,
TFUNCTION,
TUSERDATA,
TTHREADLuaValue.typename()public java.lang.String typename()
LuaValue
typename in class 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 table
istable in class LuaValuetable, otherwise falseLuaValue.checktable(),
LuaValue.opttable(LuaTable),
LuaValue.TTABLEpublic LuaTable checktable()
LuaValueLuaTable, or throw LuaError if it is not
checktable in class LuaValuethis if it is a LuaTableLuaValue.istable(),
LuaValue.opttable(LuaTable),
LuaValue.TTABLEpublic LuaTable opttable(LuaTable defval)
LuaValueLuaTable
opttable in class LuaValuedefval - LuaTable to return if this is nil or none
this 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.
presize in class LuaValuenarray - the number of array slots to preallocate in the table.
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 in class 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 in class 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_metatable
protected LuaTable changemode(boolean weakkeys,
boolean weakvalues)
weakkeys - true to make the table have weak keys going forwardweakvalues - true to make the table have weak values going forward
this or a new WeakTable if the mode change requires copying.public LuaValue get(int key)
LuaValueINDEX.
get in class LuaValuekey - the key to look up
LuaValue for that key, or NIL if not foundLuaValue.get(LuaValue),
LuaValue.rawget(int)public LuaValue get(LuaValue key)
LuaValueINDEX.
get in class LuaValuekey - the key to look up, must not be NIL or null
LuaValue for that key, or NIL if not found and no metatagLuaValue.get(int),
LuaValue.get(String),
LuaValue.rawget(LuaValue)public LuaValue rawget(int key)
LuaValue
rawget in class LuaValuekey - the key to look up
LuaValue for that key, or NIL if not foundpublic LuaValue rawget(LuaValue key)
LuaValue
rawget in class LuaValuekey - the key to look up, must not be NIL or null
LuaValue for that key, or NIL if not foundprotected LuaValue hashget(LuaValue key)
public void set(int key,
LuaValue value)
LuaValueNEWINDEX.
set in class LuaValuekey - the key to usevalue - the value to use, can be NIL, must not be null
public void set(LuaValue key,
LuaValue value)
set in class LuaValuekey - the key to use, must not be NIL or nullvalue - the value to use, can be NIL, must not be null
public void rawset(int key,
LuaValue value)
LuaValue
rawset in class LuaValuekey - the key to usevalue - the value to use, can be NIL, must not be null
public void rawset(LuaValue key,
LuaValue value)
rawset in class LuaValuekey - the key to use, must not be NIL or nullvalue - the value to use, can be NIL, must not be nullpublic LuaValue remove(int pos)
pos - the position to remove
LuaValue.NONE if not removed
public void insert(int pos,
LuaValue value)
pos - the position to removevalue - The value to insert
public LuaValue concat(LuaString sep,
int i,
int j)
Buffer
sep - LuaString separater to apply between elementsi - the first element indexj - the last element index, inclusive
LuaString value of the concatenationpublic LuaValue getn()
LuaValue
getn in class LuaValuethis is a LuaTablepublic int length()
LuaValue(#this) including metatag processing as java int
length in class LuaValueLuaValue.toint()public LuaValue len()
LuaValue(#this) including metatag processing as java int
len in class LuaValuepublic int maxn()
Provided for compatibility, not a scalable operation.
public Varargs next(LuaValue key)
next in class LuaValuekey - LuaInteger value identifying a key to start from,
or NIL to start at the beginning
LuaTable,
#inext(),
LuaValue.valueOf(int),
Varargs.arg1(),
Varargs.arg(int),
LuaValue.isnil()public Varargs inext(LuaValue key)
inext in class LuaValuekey - LuaInteger value identifying a key to start from,
or NIL to start at the beginning
LuaTable,
#next(),
LuaValue.valueOf(int),
Varargs.arg1(),
Varargs.arg(int),
LuaValue.isnil()public LuaValue foreach(LuaValue func)
func - function to callpublic LuaValue foreachi(LuaValue func)
func -
public void hashset(LuaValue key,
LuaValue value)
key - key to setvalue - value to setpublic int hashFindSlot(LuaValue key)
key - key to look for
protected void hashClearSlot(int i)
i - slot to clear.public void sort(LuaValue comparator)
comparator - LuaValue to be called to compare elements.public int keyCount()
public LuaValue[] keys()
public LuaValue eq(LuaValue val)
LuaValueEQ.
eq in class LuaValueval - The value to compare with.
TRUE if values are comparable and (this == rhs),
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)
LuaValueEQ,
and return java boolean
eq_b in class 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.EQ
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||