toString method

  1. @override
String toString()
override

Due to a dart bug, I cannot throw if we're converting a table or some other unknown data type to a string. Instead, unhandled types return their variable name wrapped in angle brackets <>. I'll check for string type conversion as-needed instead.

Implementation

@override
String toString() {
  if (isValue) {
    return switch (value) {
      // Lua promotes decimal values without fractional parts to int.
      final double d => switch ((d - d.toInt()) == 0.0) {
        true => d.toInt(),
        false => d,
      }.toString(),
      _ => value.toString(),
    };
  } else if (isRef) {
    return deref().toString();
  } else if (isNil) {
    return 'nil';
  }

  return '<$id>';
}