|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.luaj.vm.LValue
org.luaj.vm.LTable
public class LTable
Simple implementation of table structure for Lua VM. Maintains both an array part and a hash part. Does not attempt to achieve the same performance as the C version. Java code can put values in the table or get values out (bypassing the metatable, if there is one) using put() and get(). There are specializations of put() and get() for integers and Strings to avoid allocating wrapper objects when possible. remove() methods are private: setting a key's value to nil is the correct way to remove an entry from the table.
| Field Summary | |
|---|---|
protected java.lang.Object[] |
array
|
protected LValue[] |
hashKeys
|
protected java.lang.Object[] |
hashValues
|
| Fields inherited from class org.luaj.vm.LValue |
|---|
TM_INDEX, TM_METATABLE, TM_MODE, TM_NEWINDEX |
| Constructor Summary | |
|---|---|
LTable()
Construct an empty LTable with no initial capacity. |
|
LTable(int narray,
int nhash)
Construct an empty LTable that is expected to contain entries with keys in the range 1 .. |
|
| Method Summary | |
|---|---|
void |
arrayExpand(int newLength)
|
void |
arrayPresize(int minSize)
|
protected boolean |
checkLoadFactor()
|
boolean |
containsKey(int key)
Return true if the table contains an entry with the given integer-valued key, false if not. |
boolean |
containsKey(LValue key)
Return true if the table contains an entry with the given key, false if not. |
LValue |
foreach(LuaState vm,
LFunction function,
boolean indexedonly)
Executes the given f over all elements of table. |
LValue |
get(int key)
Utility method for retrieving an integer-keyed value |
LValue |
get(LValue key)
Utility method to directly get the value in a table, without metatable calls. |
int |
getArrayCapacity()
Get capacity of hash part |
int |
getHashCapacity()
Get capacity of hash part |
LValue[] |
getKeys()
Deprecated. this is not scalable. Does a linear search through the table. |
protected void |
hashClearSlot(int i)
|
int |
hashFindSlot(LValue key)
|
java.lang.Object |
hashGet(LValue key)
|
protected void |
hashRemove(LValue key)
|
void |
hashSet(LValue key,
java.lang.Object value)
|
boolean |
isTable()
Return true if this is a LTable |
LTable |
luaGetMetatable()
Valid for tables |
int |
luaGetType()
Valid for all types: return the int value identifying the type of this value |
void |
luaInsertPos(int ikey,
LValue value)
Insert element at a position in the list, shifting contiguous elements up. |
int |
luaLength()
Try to find a boundary in table `t'. |
LValue |
luaMaxN()
Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. |
LValue |
luaRemovePos(int ikey)
Remove an element from the list, moving contiguous elements down |
LTable |
luaSetMetatable(LValue metatable)
Valid for tables |
void |
luaSort(LuaState vm,
LValue compare)
|
boolean |
next(LuaState vm,
LValue key,
boolean indexedonly)
Leave key,value pair on top, or nil if at end of list. |
protected LValue |
normalizeGet(java.lang.Object val)
Check for null, and convert to nilor leave alone |
protected java.lang.Object |
normalizePut(LValue val)
Check for nil, and convert to null or leave alone |
void |
put(int key,
LValue val)
Method for putting an integer-keyed value. |
void |
put(LValue key,
LValue val)
Generic put method for all types of keys, but does not use the metatable. |
void |
put(java.lang.String key,
int val)
Utility method for putting a string key, int value directly, typically for initializing a table. |
void |
put(java.lang.String key,
LValue val)
Utility method for putting a string-keyed value directly, typically for initializing a table. |
protected void |
rehash()
|
int |
size()
Deprecated. this is not scalable. Does a linear search through the table. Use luaLength() instead. |
java.lang.String |
toJavaString()
Convert to a Java String |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.Object[] array
protected LValue[] hashKeys
protected java.lang.Object[] hashValues
| Constructor Detail |
|---|
public LTable()
public LTable(int narray,
int nhash)
| Method Detail |
|---|
public boolean isTable()
LValue
isTable in class LValuepublic int getArrayCapacity()
public int getHashCapacity()
public int size()
public void put(LValue key,
LValue val)
public void put(int key,
LValue val)
public void put(java.lang.String key,
LValue val)
public void put(java.lang.String key,
int val)
protected java.lang.Object normalizePut(LValue val)
public LValue get(LValue key)
public LValue get(int key)
protected LValue normalizeGet(java.lang.Object val)
public boolean containsKey(LValue key)
public boolean containsKey(int key)
public int luaLength()
luaLength in class LValuepublic LTable luaGetMetatable()
luaGetMetatable in class LValuepublic LTable luaSetMetatable(LValue metatable)
luaSetMetatable in class LValuepublic java.lang.String toJavaString()
LValue
toJavaString in class LValuepublic int luaGetType()
LValue
luaGetType in class LValuepublic LValue[] getKeys()
public void luaInsertPos(int ikey,
LValue value)
public LValue luaRemovePos(int ikey)
pos - position to remove, or 0 to remove last elementpublic LValue luaMaxN()
public void luaSort(LuaState vm,
LValue compare)
public boolean next(LuaState vm,
LValue key,
boolean indexedonly)
vm - the LuaState to leave the values onindexedonly - TODOindex - index to start search
public LValue foreach(LuaState vm,
LFunction function,
boolean indexedonly)
vm - function - indexedonly - is a table.foreachi() call, not a table.foreach() call
public void arrayExpand(int newLength)
public void arrayPresize(int minSize)
public void hashSet(LValue key,
java.lang.Object value)
public java.lang.Object hashGet(LValue key)
public int hashFindSlot(LValue key)
protected void hashRemove(LValue key)
protected void hashClearSlot(int i)
protected boolean checkLoadFactor()
protected void rehash()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||