org.luaj.vm2
Class WeakTable

java.lang.Object
  extended by org.luaj.vm2.WeakTable

public class WeakTable
extends java.lang.Object

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.


Nested Class Summary
static class WeakTable.WeakSlot
           
 
Constructor Summary
WeakTable(boolean weakkeys, boolean weakvalues, LuaValue backing)
          Construct a table with weak keys, weak values, or both
 
Method Summary
 LuaValue arrayget(LuaValue[] array, int index)
          Returns the value at the given index in the array, or null if it is a weak reference that has been dropped.
 org.luaj.vm2.LuaTable.Slot entry(LuaValue key, LuaValue value)
          Return an instance of Slot appropriate for the given key and value.
static LuaTable make(boolean weakkeys, boolean weakvalues)
           
protected static LuaValue strengthen(java.lang.Object ref)
          Unwrap a LuaValue from a WeakReference and/or WeakUserdata.
 LuaValue toLuaValue()
          Return this metatable as a LuaValue.
 boolean useWeakKeys()
          Return whether or not this table's keys are weak.
 boolean useWeakValues()
          Return whether or not this table's values are weak.
protected static LuaValue weaken(LuaValue value)
          Self-sent message to convert a value to its weak counterpart
 LuaValue wrap(LuaValue value)
          Returns the given value wrapped in a weak reference if appropriate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakTable

public WeakTable(boolean weakkeys,
                 boolean weakvalues,
                 LuaValue backing)
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
Method Detail

make

public static LuaTable make(boolean weakkeys,
                            boolean weakvalues)

useWeakKeys

public boolean useWeakKeys()
Return whether or not this table's keys are weak.


useWeakValues

public boolean useWeakValues()
Return whether or not this table's values are weak.


toLuaValue

public LuaValue toLuaValue()
Return this metatable as a LuaValue.


entry

public org.luaj.vm2.LuaTable.Slot entry(LuaValue key,
                                        LuaValue value)
Return an instance of Slot appropriate for the given key and value.


weaken

protected static LuaValue weaken(LuaValue value)
Self-sent message to convert a value to its weak counterpart

Parameters:
value - value to convert
Returns:
LuaValue that is a strong or weak reference, depending on type of value

strengthen

protected static LuaValue strengthen(java.lang.Object ref)
Unwrap a LuaValue from a WeakReference and/or WeakUserdata.

Parameters:
ref - reference to convert
Returns:
LuaValue or null
See Also:
weaken(LuaValue)

wrap

public LuaValue wrap(LuaValue value)
Returns the given value wrapped in a weak reference if appropriate.


arrayget

public LuaValue arrayget(LuaValue[] array,
                         int index)
Returns the value at the given index in the array, or null if it is a weak reference that has been dropped.



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