value property

Object? get value

Bumps uses by one and returns the stored _fields if a table or _value otherwise.

Implementation

Object? get value {
  uses++;
  _onRead?.call('self');

  return switch (isTable) {
    true => deref()._fields,
    false => switch (_value) {
      final LuaObject obj => obj.deref().value,
      _ => _value,
    },
  };
}
set value (Object? from)

This machinery assigns the value from to this lua object. Bumps uses by one and stores from as the new _value or _fields depending on the type of from.

Implementation

set value(Object? from) {
  uses++;
  funcDef = null;
  scope = null;
  if (from == null) {
    _value = null;
    _fields = null;
  } else if (from is LuaFieldsMap) {
    _value = null;
    _fields = from;
  } else if (from is LuaObject) {
    _value = from.deref();
    _fields = null;

    if (from.isFunc) {
      // Functions carry function definition information.
      // Copy this too.
      funcDef = from.funcDef;
      scope = from.scope;
    }
  } else {
    _value = from;
    _fields = null;
  }
  _onWrite?.call('self', from);
}