org.luaj.vm2
Class WeakTable

java.lang.Object
  extended by org.luaj.vm2.Varargs
      extended by org.luaj.vm2.LuaValue
          extended by org.luaj.vm2.LuaTable
              extended by org.luaj.vm2.WeakTable

public class WeakTable
extends LuaTable

Subclass of LuaTable that provides weak key and weak value semantics.

Normally these are not created directly, but indirectly when changing the mode of a LuaTable as lua script executes.

However, calling the constructors directly when weak tables are required from Java will reduce overhead.


Field Summary
 
Fields inherited from class org.luaj.vm2.LuaTable
array, hashEntries, hashKeys, hashValues, m_metatable
 
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
  WeakTable(boolean weakkeys, boolean weakvalues)
          Construct a table with weak keys, weak values, or both
protected WeakTable(boolean weakkeys, boolean weakvalues, int narray, int nhash)
          Construct a table with weak keys, weak values, or both, and an initial capacity
protected WeakTable(boolean weakkeys, boolean weakvalues, LuaTable source)
          Construct a table with weak keys, weak values, or both, and a source of initial data
 
Method Summary
protected  LuaTable changemode(boolean weakkeys, boolean weakvalues)
          Change the mode of a table
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.
 int hashFindSlot(LuaValue key)
          Find the hashtable slot to use
protected  LuaValue hashget(LuaValue key)
          Get the hash value for a key key the key to look up
 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
 void presize(int narray)
          Preallocate the array part of a table to be a certain size,
 void presize(int narray, int nhash)
          Presize capacity of both array and hash parts.
 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
 void sort(LuaValue comparator)
          Sort the table using a comparator.
 
Methods inherited from class org.luaj.vm2.LuaTable
checktable, concat, eq_b, eq, foreach, foreachi, get, get, getmetatable, getn, hashClearSlot, hashset, inext, insert, istable, keyCount, keys, len, length, opttable, remove, set, set, setmetatable, type, typename
 
Methods inherited from class org.luaj.vm2.LuaValue
add, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, buffer, call, call, call, call, callmt, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checkthread, checkuserdata, checkuserdata, checkvalidkey, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eqmtcall, equals, error, get, getfenv, gettable, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, illegal, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, isnumber, isstring, isthread, isuserdata, isuserdata, isweaknil, lenerror, listOf, listOf, load, lt_b, lt_b, lt_b, lt, lt, lt, lteq_b, lteq_b, lteq_b, lteq, lteq, lteq, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq_b, neq, 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, setfenv, settable, strcmp, strcmp, strongkey, strongvalue, strvalue, sub, sub, sub, 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, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf
 
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
 

Constructor Detail

WeakTable

public WeakTable(boolean weakkeys,
                 boolean weakvalues)
Construct a table with weak keys, weak values, or both

Parameters:
weakkeys - true to let the table have weak keys
weakvalues - true to let the table have weak values

WeakTable

protected WeakTable(boolean weakkeys,
                    boolean weakvalues,
                    int narray,
                    int nhash)
Construct a table with weak keys, weak values, or both, and an initial capacity

Parameters:
weakkeys - true to let the table have weak keys
weakvalues - true to let the table have weak values
narray - capacity of array part
nhash - capacity of hash part

WeakTable

protected WeakTable(boolean weakkeys,
                    boolean weakvalues,
                    LuaTable source)
Construct a table with weak keys, weak values, or both, and a source of initial data

Parameters:
weakkeys - true to let the table have weak keys
weakvalues - true to let the table have weak values
source - LuaTable containing the initial elements
Method Detail

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.

Overrides:
presize in class LuaTable
Parameters:
narray - the number of array slots to preallocate in the table.

presize

public void presize(int narray,
                    int nhash)
Presize capacity of both array and hash parts.

Overrides:
presize in class LuaTable
Parameters:
narray - capacity of array part
nhash - capacity of hash part

getArrayLength

protected int getArrayLength()
Description copied from class: LuaTable
Get the length of the array part of the table.

Overrides:
getArrayLength in class LuaTable
Returns:
length of the array part, does not relate to count of objects in the table.

getHashLength

protected int getHashLength()
Description copied from class: LuaTable
Get the length of the hash part of the table.

Overrides:
getHashLength in class LuaTable
Returns:
length of the hash part, does not relate to count of objects in the table.

changemode

protected LuaTable changemode(boolean weakkeys,
                              boolean weakvalues)
Description copied from class: LuaTable
Change the mode of a table

Overrides:
changemode in class LuaTable
Parameters:
weakkeys - true to make the table have weak keys going forward
weakvalues - true to make the table have weak values going forward
Returns:
this or a new WeakTable if the mode change requires copying.

rawset

public void rawset(int key,
                   LuaValue value)
Description copied from class: LuaValue
Set a value in a table without metatag processing.

Overrides:
rawset in class LuaTable
Parameters:
key - the key to use
value - the value to use, can be NIL, must not be null

rawset

public void rawset(LuaValue key,
                   LuaValue value)
Description copied from class: LuaTable
caller must ensure key is not nil

Overrides:
rawset in class LuaTable
Parameters:
key - the key to use, must not be NIL or null
value - the value to use, can be NIL, must not be null

rawget

public LuaValue rawget(int key)
Description copied from class: LuaValue
Get a value in a table without metatag processing.

Overrides:
rawget in class LuaTable
Parameters:
key - the key to look up
Returns:
LuaValue for that key, or NIL if not found

rawget

public LuaValue rawget(LuaValue key)
Description copied from class: LuaValue
Get a value in a table without metatag processing.

Overrides:
rawget in class LuaTable
Parameters:
key - the key to look up, must not be NIL or null
Returns:
LuaValue for that key, or NIL if not found

hashget

protected LuaValue hashget(LuaValue key)
Get the hash value for a key key the key to look up

Overrides:
hashget in class LuaTable

hashFindSlot

public int hashFindSlot(LuaValue key)
Description copied from class: LuaTable
Find the hashtable slot to use

Overrides:
hashFindSlot in class LuaTable
Parameters:
key - key to look for
Returns:
slot to use

maxn

public int maxn()
Description copied from class: LuaTable
Return table.maxn() as defined by lua 5.0.

Provided for compatibility, not a scalable operation.

Overrides:
maxn in class LuaTable
Returns:
value for maxn

next

public Varargs next(LuaValue key)
Get the next element after a particular key in the table

Overrides:
next in class LuaTable
Parameters:
key - LuaInteger value identifying a key to start from, or NIL to start at the beginning
Returns:
key,value or nil
See Also:
LuaTable, #inext(), LuaValue.valueOf(int), Varargs.arg1(), Varargs.arg(int), LuaValue.isnil()

sort

public void sort(LuaValue comparator)
Description copied from class: LuaTable
Sort the table using a comparator.

Overrides:
sort in class LuaTable
Parameters:
comparator - LuaValue to be called to compare elements.


Copyright © 2007-2008 Luaj.org. All Rights Reserved.