toC method
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:
- Value-type (StructDLiteral): always allocates a
fresh slot (or reuse) in
tempand writes into it via allocateInto. - Pointer-owning, with originalPointer: syncs Dart fields back into
the existing native pointer via syncInto and returns it directly.
Skipped entirely if the instance isDisposed or
temp.doSyncis false. - Pointer-owning, without originalPointer: allocates a new slot, populates it via allocateInto, and stores the result as originalPointer.
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!;
}