Value class

Represents a value in the LuaLike runtime system.

Values can hold any Dart object and optionally have an associated metatable that defines their behavior for various operations. Values that represent tables implement the Map interface for easy interaction with Dart code.

Implemented types
Available extensions

Constructors

Value(dynamic raw, {Map<String, dynamic>? metatable, bool isMulti = false, bool isConst = false, bool isToBeClose = false, bool isTempKey = false, bool skipAllocationDebt = false, bool skipGcRegistration = false, bool isSharedPrimitive = false, List<Upvalue>? upvalues, LuaRuntime? interpreter, FunctionBody? functionBody, Environment? closureEnvironment, String? functionName, int? debugLineDefined, bool strippedDebugInfo = false})
Creates a new Value wrapping the given raw value.
Value.constant(dynamic value, {Map<String, dynamic>? metatable})
Creates a constant value that cannot be modified after initialization
factory
Value.multi(List values)
factory
Value.primitive(Object? raw, {bool isMulti = false, bool isConst = false, bool isToBeClose = false, bool isTempKey = false, bool skipAllocationDebt = false, bool skipGcRegistration = false, bool isSharedPrimitive = false, bool isRawPrimitive = false, List<Upvalue>? upvalues, LuaRuntime? interpreter, FunctionBody? functionBody, Environment? closureEnvironment, String? functionName, int? debugLineDefined, bool strippedDebugInfo = false})
Value.toBeClose(dynamic value, {Map<String, dynamic>? metatable})
factory
Value.transientPrimitive(Object? raw, {LuaRuntime? interpreter})

Properties

cachedHasWeakValues → bool
Cached-only check for weak-values mode, using the last observed '__mode' string from setMetatable. Useful when the live metatable is already freed but we still need to honor semantics for this cycle.
no setter
canStoreAsRawLuaSlot → bool
Whether storing only this wrapper's raw slot preserves all observable Lua semantics. Values with side metadata or closure state must retain their wrapper identity (for example, primitive metatables and __name).
no setter
closureEnvironment ↔ Environment?
Captured environment for Lua functions to support coroutine cloning.
getter/setter pair
comparatorCounterBox ↔ Box?
Captured counter box for counted comparator fast paths.
getter/setter pair
debugLineDefined ↔ int?
Source line (0-based) where the function definition begins.
getter/setter pair
defaultMetatableGeneration ↔ int
getter/setter pair
entries → Iterable<MapEntry<String, dynamic>>
The map entries of this Map.
no setteroverride
estimatedSize → int
Estimated memory footprint for this object expressed in GC "credits".
no setter
finalizerEligible ↔ bool
Whether this object is eligible for finalization. Per Lua semantics, an object is only finalized if its metatable had a __gc field when the metatable was set (KIN-23). Adding __gc later does not retroactively make the object finalizable.
getter/setter pair
functionBody ↔ FunctionBody?
The AST node representing the function body, if this value is a Lua function.
getter/setter pair
functionName ↔ String?
The name of the function, if this value is a named function.
getter/setter pair
gcCredits ↔ int?
Cached memory credits tracked for this object, or null if untracked.
getter/setter pairinherited
gcExcluded ↔ bool
Whether this object should be counted as excluded from Lua-visible allocation credits.
getter/setter pairinherited
gcSpace ↔ GCGenerationSpace?
Which GC generation space this object is tracked in, or null if untracked. Stored directly on the object to avoid Expando lookups on hot paths.
getter/setter pairinherited
globalProxyEnvironment ↔ Environment?
Backing environment for the canonical _G proxy table.
getter/setter pair
hashCode → int
The hash code for this object.
no setteroverride
hasWeakKeys → bool
Whether this table has weak keys (ephemeron behavior)
no setter
hasWeakValues → bool
Whether this table has weak values (does not mark through values)
no setter
interpreter ↔ LuaRuntime?
Runtime instance associated with this value, when one is needed. Inline when no metadata exists; delegates to metadata otherwise.
getter/setter pair
isAllWeak → bool
Whether this table is all-weak (both keys and values are weak)
no setter
isConst ↔ bool
Whether this value is a constant (cannot be modified after initialization)
getter/setter pair
isCountedLessComparator ↔ bool
Hint for a comparator of the form function(x, y) counter = counter + 1; return x < y end. This preserves the counter side effect while still allowing the sort path to bypass a full Lua closure call for primitive comparisons.
getter/setter pair
isCountedLessComparatorReversed ↔ bool
Hint for a comparator of the form function(x, y) counter = counter + 1; return y < x end.
getter/setter pair
isEmpty → bool
Whether there is no key/value pair in the map.
no setteroverride
isFreed → bool
Whether this value has been freed by the GC.
no setter
isLessComparator ↔ bool
Hint for fast-calling simple Lua closures (e.g., comparator x < y) Currently used to accelerate very common patterns in tight loops.
getter/setter pair
isLessComparatorReversed ↔ bool
Hint for simple reversed comparator closures of the form function(x, y) return y < x end. Used to accelerate validation checks in tight loops.
getter/setter pair
isMulti ↔ bool
Whether this value is a multi-result value.
getter/setter pair
isNilReturningClosure ↔ bool
Hint for trivial closures that always return nil (e.g., function(x, y) return nil end). This allows the interpreter to bypass creating an execution environment and skip the closure call, while still evaluating argument expressions for side effects.
getter/setter pair
isNotEmpty → bool
Whether there is at least one key/value pair in the map.
no setteroverride
isOld ↔ bool
Whether this value is old (used for garbage collection)
getter/setter pair
isPrimitiveLike → bool
Primitive-like values for weak-table semantics: numbers, booleans, nil, BigInt, and strings. In Lua's weak tables, strings and numbers behave as immediate values for clearing logic used by tests like gc.lua (e.g., keeping number->string survivors in weak-values tables and allowing string->string survivors in all-weak tables).
no setter
isRawPrimitive ↔ bool
Whether this Value wraps a raw primitive (int, double, bool, null). The GC skips these during marking — they contain no heap references.
getter/setter pair
isSharedPrimitive ↔ bool
Whether this wrapper belongs to the runtime's shared primitive cache.
getter/setter pair
isStringLike → bool
no setter
isTable → bool
Whether this value represents a table
no setter
isTempKey ↔ bool
Whether this value is a temporary key used for table lookups. Temporary keys are not counted for GC debt to avoid tracking overhead.
getter/setter pair
isToBeClose ↔ bool
Whether this value is a to-be-closed variable
getter/setter pair
keys → Iterable<String>
The keys of this Map.
no setteroverride
length → int
The number of key/value pairs in the map.
no setteroverride
marked ↔ bool
Whether this object has been marked during the current GC cycle. Used in mark-and-sweep collection to identify live objects.
getter/setter pair
metatable ↔ Map<String, dynamic>?
getter/setter pair
metatableOwnerHasWeakValues → bool
no setter
metatableRef ↔ Value?
Reference to the original metatable Value when set via setmetatable.
getter/setter pair
multiResults → List<Object?>?
Values carried by this public multi-result wrapper, if any.
no setter
raw ↔ dynamic
Get the raw value
getter/setter pair
rawObject → Object?
Same as raw but typed as Object?.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shouldCountGcAllocation → bool
Whether GC registration should charge this value to Lua-visible memory.
no setter
skipAllocationDebt ↔ bool
Whether this wrapper should be excluded from allocation-debt accounting.
getter/setter pair
skipGcRegistration ↔ bool
Whether this wrapper should skip eager GC registration.
getter/setter pair
strippedDebugInfo ↔ bool
Whether debug inspection should behave like a stripped Lua chunk.
getter/setter pair
tableVersion → int
Incrementing version that changes every time the underlying table mutates.
no setter
tableWeakMode → String?
Gets the weak mode of this table from its metatable's __mode field. Returns null if this is not a table or has no __mode. Returns 'k' for weak keys, 'v' for weak values, 'kv' for both.
no setter
upvalues ↔ List<Upvalue>?
References to captured upvalues if this value represents a function/closure.
getter/setter pair
values → Iterable
The values of this Map.
no setteroverride

Methods

addAll(Map<String, dynamic> other) → void
Adds all key/value pairs of other to this map.
override
addEntries(Iterable<MapEntry<String, dynamic>> newEntries) → void
Adds all key/value pairs of newEntries to this map.
override
and(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

call(List<Object?> args) → Future<Object?>
Calls this value if it's callable (continued)
callMetamethod(String s, List<Value> list) → Object?
callMetamethodAsync(String s, List<Value> list) → Future<Object?>
Asynchronous version of callMetamethod for use in async contexts
cast<K, V>() → Map<RK, RV>
Provides a view of this map as having RK keys and RV instances, if necessary.
override
clear() → void
Removes all entries from the map.
override
close([dynamic error]) → Future<void>
Closes the value by calling its __close metamethod if it exists error - The error that caused the scope to exit, or null if normal exit
completeUnwrap() → dynamic
concat(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

containsKey(Object? key) → bool
Whether this map contains the given key.
override
containsValue(Object? value) → bool
Whether this map contains the given value.
override
copy() → Value
Creates a deep copy of this Value and its metatable.
equals(Object other) → bool

Available on Value, provided by the OperatorExtension extension

exp(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

forEach(void action(String key, Value value)) → void
Applies action to each key/value pair of the map.
override
free() → void
Free any resources (for debugging or finalization).
getMetamethod(String event) → dynamic
Looks up a metamethod in this value's metatable.
getMetatable() → Map<String, dynamic>?
Gets the metatable associated with this value.
getReferences() → List<Object?>
Return direct references so the GC can traverse the object graph.
getReferencesForGC({required bool strongKeys, required bool strongValues}) → List<Object?>
Gets references for GC traversal with control over weak semantics. This is used internally by the GC to implement weak table behavior.
getValueAsync(Object? key) → Future
Asynchronous version of operator [] that awaits any __index metamethod results. This is needed when metamethods are implemented as Lua functions which return Futures.
hasMetamethod(String event) → bool
Checks if the value has a metamethod associated with the given event.
invoke(List<Object?> args) → Future<Object?>
Calls the value as a function with the given arguments.
isA<T>() → bool
isCallable() → bool
Checks if this value is callable (is a function or has __call metamethod)
isFalsy() → bool

Available on Value, provided by the OperatorExtension extension

isTruthy() → bool

Available on Value, provided by the OperatorExtension extension

map<K, V>(MapEntry<K, V> convert(String key, dynamic value)) → Map<K, V>
Returns a new map where all entries of this map are transformed by the given convert function.
override
markTableModified() → void
Marks the underlying table as modified so cached lookups can be invalidated.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notEquals(Object other) → bool

Available on Value, provided by the OperatorExtension extension

noteRawTableMutation() → void
Records a raw mutation to this table that bypassed normal Value writes.
or(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

putIfAbsent(String key, dynamic ifAbsent()) → dynamic
Look up the value of key, or add a new entry if it isn't there.
override
rawContainsKey(Object? key) → bool
Checks if the raw table contains the key (without metamethods)
remove(Object? key) → dynamic
Removes key and its associated value, if present, from the map.
override
removeWhere(bool test(String key, dynamic value)) → void
Removes all entries of this map that satisfy the given test.
override
revive() → void
Clear a stale freed marker when this value is rediscovered from a live root in a later collection cycle.
setMetatable(Map<String, dynamic> mt, {Object? ownerRaw}) → void
Sets a new metatable for this value.
setNumericIndex(int index, Value value) → void
Directly assigns value to the numeric index index without performing additional key normalization. Intended for dense-array fast paths where metamethods are known to be absent.
setValueAsync(Object key, dynamic value, [Set<Value>? visited]) → Future<void>
Assigns value to key, awaiting any __newindex metamethod.
tableEntriesForGC() → Iterable<MapEntry>
Returns table entries for GC processing. Used internally by the GC to access table contents for weak clearing.
toString() → String
A string representation of this object.
override
unwrap() → dynamic
Unwraps a Value to get its raw value, recursively for tables and lists.
update(String key, dynamic update(dynamic value), {dynamic ifAbsent()?}) → dynamic
Updates the value for the provided key.
override
updateAll(dynamic update(String key, dynamic value)) → void
Updates all values.
override

Operators

operator %(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator &(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator *(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator +(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

Overload the addition operator
operator -(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator /(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator <(Object other) → dynamic

Available on Value, provided by the OperatorExtension extension

operator <<(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator <=(Object other) → dynamic

Available on Value, provided by the OperatorExtension extension

operator ==(Object other) → bool
The equality operator.
override
operator >(Object other) → dynamic

Available on Value, provided by the OperatorExtension extension

operator >=(Object other) → dynamic

Available on Value, provided by the OperatorExtension extension

operator >>(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator [](Object? key) → dynamic
The value for the given key, or null if key is not in the map.
override
operator []=(Object key, dynamic value) → void
Associates the key with the given value.
override
operator ^(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator unary-() → Value

Available on Value, provided by the OperatorExtension extension

operator |(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

operator ~() → Value

Available on Value, provided by the OperatorExtension extension

operator ~/(dynamic other) → Value

Available on Value, provided by the OperatorExtension extension

Static Methods

adjustStringKeyCreditsForMap(Map map, Object? key, int deltaChars) → void
Adjusts cached string-key credits for a raw Map when entries are mutated externally (e.g., by the GC during weak-table clearing). deltaChars is character count; multiplied by stringUnit.
allocationDiagnostics() → Map<String, Object>
Returns exact constructor counts when allocation diagnostics are enabled.
invalidateStringKeyCache(Map map) → void
Invalidates the cached string-key credits for a raw Map. This forces estimatedSize to recalculate from scratch on next access. Used by GC when removing multiple keys to avoid double-decrement bugs.
listToLuaTable(List list) → Map<int, dynamic>
lookupCanonicalTableWrapper(Object? table) → Value?
Public helper to retrieve the canonical wrapper for a raw Map-backed table, if one is registered. Returns null if none is registered or the value is not a Map.
rawMetatableOwnerForTable(Object? table) → Object?
rawTableIsMetatable(Object? table) → bool
Whether this raw table is currently used as a metatable. Writes to such tables must preserve Value wrappers because metamethod dispatch observes their type and metadata directly.
registerTableIdentity(Value v) → void
Register v as the canonical wrapper for its underlying Map, so that subsequent lookups will return v and preserve its metatable/identity.
resetAllocationDiagnostics() → void
Resets opt-in allocation counters used by profile-mode harnesses.
tableObjectHasWeakValues(Object? table) → bool
weakModeForTableObject(Object? table) → String?
wrap(dynamic value) → Value
value - The value to wrap Returns a new Value instance wrapping the input.