toC method

  1. @nonVirtual
Pointer<C> toC(
  1. RaylibTemp temp,
  2. String key
)

Returns a native pointer for this struct, allocating or syncing as needed.

This is the primary entry point for passing a StructD to a C call. The behavior depends on the struct type and state:

key is incorporated into the slot key to allow the same instance to occupy distinct slots within the same frame (see setTag).

Implementation

@nonVirtual
Pointer<C> toC(RaylibTemp temp, String key) {
  String baseKey = _getBaseKey(key);

  if (!_requiresOriginalPointer) {
    _allocKey = baseKey;
    final p = allocatePointer(temp, baseKey);
    allocateInto(temp, p, baseKey);
    return p;
  }

  if (_internalId == -1) _internalId = ++_internalIdCounter;
  if (!isDisposed) _warnIfNoOriginalPointer(temp);

  baseKey = _getBaseKeyWithId(key);

  if (originalPointer != null) {
    temp.debugSyncInfo('[SYNC] $structName.syncInto($baseKey)');
    if (isDisposed) return originalPointer!;
    if (!temp.doSync) return originalPointer!;

    syncInto(temp, originalPointer!, baseKey);
    return originalPointer!;
  }

  temp.debugSyncInfo('[SYNC] $structName.allocatePointer($baseKey)');
  _allocKey = baseKey;
  final p = allocatePointer(temp, baseKey);
  allocateInto(temp, p, baseKey);
  originalPointer = p;
  return originalPointer!;
}