Adopted the standard withCString for C strings throughout the library.

This commit is contained in:
2026-09-18 11:58:57 +02:00
parent 575165dec4
commit 89c8d7a04c
22 changed files with 71 additions and 115 deletions
@@ -26,7 +26,7 @@ extension Graphics {
/// Loads a bitmap from a file in the game's pdx or Data directory.
public convenience init(path: String) throws(PlaydateError) {
var error: UnsafePointer<CChar>?
let pointer = path.withPlaydateCString { gfx.pointee.loadBitmap.unsafelyUnwrapped($0, &error) }
let pointer = path.withCString { gfx.pointee.loadBitmap.unsafelyUnwrapped($0, &error) }
guard let pointer else { throw PlaydateError(cString: error) }
self.init(pointer: pointer, isOwned: true)
}
@@ -77,7 +77,7 @@ extension Graphics {
/// Replaces the bitmap's contents with the image at `path`.
public func load(path: String) throws(PlaydateError) {
var error: UnsafePointer<CChar>?
path.withPlaydateCString { gfx.pointee.loadIntoBitmap.unsafelyUnwrapped($0, pointer, &error) }
path.withCString { gfx.pointee.loadIntoBitmap.unsafelyUnwrapped($0, pointer, &error) }
cachedSize = nil
if let error { throw PlaydateError(cString: error) }
}