Adopted the standard withCString for C strings throughout the library.
This commit is contained in:
@@ -25,12 +25,12 @@ extension System {
|
||||
|
||||
/// Logs a message to the console (device serial or simulator console).
|
||||
public static func log(_ message: String) {
|
||||
message.withPlaydateCString { cplaydate_log(Playdate.apiPointer, $0) }
|
||||
message.withCString { cplaydate_log(Playdate.apiPointer, $0) }
|
||||
}
|
||||
|
||||
/// Stops execution and displays the message as a fatal error.
|
||||
public static func error(_ message: String) {
|
||||
message.withPlaydateCString { cplaydate_error(Playdate.apiPointer, $0) }
|
||||
message.withCString { cplaydate_error(Playdate.apiPointer, $0) }
|
||||
}
|
||||
|
||||
// MARK: - Time
|
||||
@@ -208,7 +208,7 @@ extension System {
|
||||
@discardableResult
|
||||
public static func addMenuItem(title: String, onSelect: @escaping (MenuItem) -> Void) -> MenuItem? {
|
||||
var item: MenuItem?
|
||||
title.withPlaydateCString { cTitle in
|
||||
title.withCString { cTitle in
|
||||
let pointer = api.pointee.addMenuItem.unsafelyUnwrapped(cTitle, menuItemTrampoline, nil)
|
||||
item = MenuItem(pointer: pointer, onSelect: onSelect)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ extension System {
|
||||
public static func addCheckmarkMenuItem(title: String, isChecked: Bool = false,
|
||||
onSelect: @escaping (MenuItem) -> Void) -> MenuItem? {
|
||||
var item: MenuItem?
|
||||
title.withPlaydateCString { cTitle in
|
||||
title.withCString { cTitle in
|
||||
let pointer = api.pointee.addCheckmarkMenuItem.unsafelyUnwrapped(
|
||||
cTitle, isChecked ? 1 : 0, menuItemTrampoline, nil)
|
||||
item = MenuItem(pointer: pointer, onSelect: onSelect)
|
||||
@@ -237,7 +237,7 @@ extension System {
|
||||
let copies = options.map { $0.copiedPlaydateCString() }
|
||||
var cOptions: [UnsafePointer<CChar>?] = copies.map { UnsafePointer($0) }
|
||||
var item: MenuItem?
|
||||
title.withPlaydateCString { cTitle in
|
||||
title.withCString { cTitle in
|
||||
cOptions.withUnsafeMutableBufferPointer { buffer in
|
||||
let pointer = api.pointee.addOptionsMenuItem.unsafelyUnwrapped(
|
||||
cTitle, buffer.baseAddress, Int32(options.count), menuItemTrampoline, nil)
|
||||
@@ -291,7 +291,7 @@ extension System {
|
||||
/// Quits the current game and restarts it with the given launch arguments.
|
||||
public static func restartGame(launchArguments: String? = nil) {
|
||||
if let launchArguments {
|
||||
launchArguments.withPlaydateCString { api.pointee.restartGame.unsafelyUnwrapped($0) }
|
||||
launchArguments.withCString { api.pointee.restartGame.unsafelyUnwrapped($0) }
|
||||
} else {
|
||||
api.pointee.restartGame.unsafelyUnwrapped(nil)
|
||||
}
|
||||
@@ -321,7 +321,7 @@ extension System {
|
||||
|
||||
/// Looks up a localized string by key from the game's strings files.
|
||||
public static func localizedText(forKey key: String, language: Language = .system) -> String? {
|
||||
key.withPlaydateCString { cKey in
|
||||
key.withCString { cKey in
|
||||
guard let cString = api.pointee.getLocalizedText.unsafelyUnwrapped(cKey, language.cValue) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user