Wrapped C enum raw values in explicit width conversions throughout the PlayDate binding target.
This commit is contained in:
@@ -27,15 +27,15 @@ extension File {
|
|||||||
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
||||||
|
|
||||||
/// Read from the game pdx, then the Data directory.
|
/// Read from the game pdx, then the Data directory.
|
||||||
public static let read = Options(rawValue: kFileRead.rawValue)
|
public static let read = Options(rawValue: UInt32(kFileRead.rawValue))
|
||||||
/// Read from the Data directory only.
|
/// Read from the Data directory only.
|
||||||
public static let readData = Options(rawValue: kFileReadData.rawValue)
|
public static let readData = Options(rawValue: UInt32(kFileReadData.rawValue))
|
||||||
/// Write to the Data directory, truncating an existing file.
|
/// Write to the Data directory, truncating an existing file.
|
||||||
public static let write = Options(rawValue: kFileWrite.rawValue)
|
public static let write = Options(rawValue: UInt32(kFileWrite.rawValue))
|
||||||
/// Write to the Data directory, appending to an existing file.
|
/// Write to the Data directory, appending to an existing file.
|
||||||
public static let append = Options(rawValue: kFileAppend.rawValue)
|
public static let append = Options(rawValue: UInt32(kFileAppend.rawValue))
|
||||||
|
|
||||||
var cValue: FileOptions { FileOptions(rawValue) }
|
var cValue: FileOptions { FileOptions(FileOptions.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about a file or directory, mirroring `FileStat`.
|
/// Information about a file or directory, mirroring `FileStat`.
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ extension Graphics {
|
|||||||
case clear = 2
|
case clear = 2
|
||||||
case xor = 3
|
case xor = 3
|
||||||
|
|
||||||
init(_ color: LCDSolidColor) { self = SolidColor(rawValue: color.rawValue) ?? .clear }
|
init(_ color: LCDSolidColor) { self = SolidColor(rawValue: UInt32(color.rawValue)) ?? .clear }
|
||||||
var cValue: LCDSolidColor { LCDSolidColor(rawValue) }
|
var cValue: LCDSolidColor { LCDSolidColor(LCDSolidColor.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How source pixels combine with the destination when drawing.
|
/// How source pixels combine with the destination when drawing.
|
||||||
@@ -88,8 +88,8 @@ extension Graphics {
|
|||||||
case nxor = 6
|
case nxor = 6
|
||||||
case inverted = 7
|
case inverted = 7
|
||||||
|
|
||||||
init(_ mode: LCDBitmapDrawMode) { self = DrawMode(rawValue: mode.rawValue) ?? .copy }
|
init(_ mode: LCDBitmapDrawMode) { self = DrawMode(rawValue: UInt32(mode.rawValue)) ?? .copy }
|
||||||
var cValue: LCDBitmapDrawMode { LCDBitmapDrawMode(rawValue) }
|
var cValue: LCDBitmapDrawMode { LCDBitmapDrawMode(LCDBitmapDrawMode.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mirroring applied when drawing a bitmap.
|
/// Mirroring applied when drawing a bitmap.
|
||||||
@@ -99,8 +99,8 @@ extension Graphics {
|
|||||||
case flippedY = 2
|
case flippedY = 2
|
||||||
case flippedXY = 3
|
case flippedXY = 3
|
||||||
|
|
||||||
init(_ flip: LCDBitmapFlip) { self = BitmapFlip(rawValue: flip.rawValue) ?? .unflipped }
|
init(_ flip: LCDBitmapFlip) { self = BitmapFlip(rawValue: UInt32(flip.rawValue)) ?? .unflipped }
|
||||||
var cValue: LCDBitmapFlip { LCDBitmapFlip(rawValue) }
|
var cValue: LCDBitmapFlip { LCDBitmapFlip(LCDBitmapFlip.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The end cap style used when drawing lines.
|
/// The end cap style used when drawing lines.
|
||||||
@@ -109,7 +109,7 @@ extension Graphics {
|
|||||||
case square = 1
|
case square = 1
|
||||||
case round = 2
|
case round = 2
|
||||||
|
|
||||||
var cValue: LCDLineCapStyle { LCDLineCapStyle(rawValue) }
|
var cValue: LCDLineCapStyle { LCDLineCapStyle(LCDLineCapStyle.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The encoding of text passed to the text functions.
|
/// The encoding of text passed to the text functions.
|
||||||
@@ -118,7 +118,7 @@ extension Graphics {
|
|||||||
case utf8 = 1
|
case utf8 = 1
|
||||||
case utf16LittleEndian = 2
|
case utf16LittleEndian = 2
|
||||||
|
|
||||||
var cValue: PDStringEncoding { PDStringEncoding(rawValue) }
|
var cValue: PDStringEncoding { PDStringEncoding(PDStringEncoding.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The winding rule used by `fillPolygon`.
|
/// The winding rule used by `fillPolygon`.
|
||||||
@@ -126,7 +126,7 @@ extension Graphics {
|
|||||||
case nonZero = 0
|
case nonZero = 0
|
||||||
case evenOdd = 1
|
case evenOdd = 1
|
||||||
|
|
||||||
var cValue: LCDPolygonFillRule { LCDPolygonFillRule(rawValue) }
|
var cValue: LCDPolygonFillRule { LCDPolygonFillRule(LCDPolygonFillRule.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How text wraps in `drawText(in:)`.
|
/// How text wraps in `drawText(in:)`.
|
||||||
@@ -135,7 +135,7 @@ extension Graphics {
|
|||||||
case character = 1
|
case character = 1
|
||||||
case word = 2
|
case word = 2
|
||||||
|
|
||||||
var cValue: PDTextWrappingMode { PDTextWrappingMode(rawValue) }
|
var cValue: PDTextWrappingMode { PDTextWrappingMode(PDTextWrappingMode.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Horizontal alignment for `drawText(in:)`.
|
/// Horizontal alignment for `drawText(in:)`.
|
||||||
@@ -144,7 +144,7 @@ extension Graphics {
|
|||||||
case center = 1
|
case center = 1
|
||||||
case right = 2
|
case right = 2
|
||||||
|
|
||||||
var cValue: PDTextAlignment { PDTextAlignment(rawValue) }
|
var cValue: PDTextAlignment { PDTextAlignment(PDTextAlignment.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An integer rectangle mirroring `LCDRect`. `right` and `bottom` are
|
/// An integer rectangle mirroring `LCDRect`. `right` and `bottom` are
|
||||||
|
|||||||
@@ -57,12 +57,12 @@ extension JSON {
|
|||||||
/// Converts a C `json_value`, consuming any container box it references.
|
/// Converts a C `json_value`, consuming any container box it references.
|
||||||
private static func convert(_ value: json_value) -> Value {
|
private static func convert(_ value: json_value) -> Value {
|
||||||
switch UInt32(bitPattern: Int32(value.type)) {
|
switch UInt32(bitPattern: Int32(value.type)) {
|
||||||
case kJSONTrue.rawValue: return .bool(true)
|
case UInt32(kJSONTrue.rawValue): return .bool(true)
|
||||||
case kJSONFalse.rawValue: return .bool(false)
|
case UInt32(kJSONFalse.rawValue): return .bool(false)
|
||||||
case kJSONInteger.rawValue: return .int(Int(value.data.intval))
|
case UInt32(kJSONInteger.rawValue): return .int(Int(value.data.intval))
|
||||||
case kJSONFloat.rawValue: return .float(value.data.floatval)
|
case UInt32(kJSONFloat.rawValue): return .float(value.data.floatval)
|
||||||
case kJSONString.rawValue: return .string(String(playdateCString: value.data.stringval) ?? "")
|
case UInt32(kJSONString.rawValue): return .string(String(playdateCString: value.data.stringval) ?? "")
|
||||||
case kJSONArray.rawValue, kJSONTable.rawValue:
|
case UInt32(kJSONArray.rawValue), UInt32(kJSONTable.rawValue):
|
||||||
guard let pointer = value.data.arrayval else { return .null }
|
guard let pointer = value.data.arrayval else { return .null }
|
||||||
return Unmanaged<ValueBox>.fromOpaque(pointer).takeRetainedValue().value
|
return Unmanaged<ValueBox>.fromOpaque(pointer).takeRetainedValue().value
|
||||||
default: return .null
|
default: return .null
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ extension Lua {
|
|||||||
case thread = 7
|
case thread = 7
|
||||||
case object = 8
|
case object = 8
|
||||||
|
|
||||||
init(_ type: LuaType) { self = Kind(rawValue: type.rawValue) ?? .nil }
|
init(_ type: LuaType) { self = Kind(rawValue: UInt32(type.rawValue)) ?? .nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A constant published on a registered class.
|
/// A constant published on a registered class.
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ extension Network {
|
|||||||
case unknown = 1
|
case unknown = 1
|
||||||
|
|
||||||
init(_ error: PDNetErr) {
|
init(_ error: PDNetErr) {
|
||||||
self = NetError(rawValue: error.rawValue) ?? .unknown
|
self = NetError(rawValue: Int32(error.rawValue)) ?? .unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ extension Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static var status: WifiStatus {
|
public static var status: WifiStatus {
|
||||||
WifiStatus(rawValue: networkAPI.pointee.getStatus.unsafelyUnwrapped().rawValue) ?? .notConnected
|
WifiStatus(rawValue: UInt32(networkAPI.pointee.getStatus.unsafelyUnwrapped().rawValue)) ?? .notConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turns the wifi radio on or off. The completion receives `nil` on
|
/// Turns the wifi radio on or off. The completion receives `nil` on
|
||||||
@@ -115,7 +115,7 @@ extension Network {
|
|||||||
// The callback will not be invoked; balance the retain.
|
// The callback will not be invoked; balance the retain.
|
||||||
box.release()
|
box.release()
|
||||||
}
|
}
|
||||||
return AccessReply(rawValue: reply.rawValue) ?? .ask
|
return AccessReply(rawValue: UInt32(reply.rawValue)) ?? .ask
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - HTTP
|
// MARK: - HTTP
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ extension Sound {
|
|||||||
case monoADPCM = 4
|
case monoADPCM = 4
|
||||||
case stereoADPCM = 5
|
case stereoADPCM = 5
|
||||||
|
|
||||||
init(_ format: SoundFormat) { self = Format(rawValue: format.rawValue) ?? .mono16bit }
|
init(_ format: SoundFormat) { self = Format(rawValue: UInt32(format.rawValue)) ?? .mono16bit }
|
||||||
var cValue: SoundFormat { SoundFormat(rawValue) }
|
var cValue: SoundFormat { SoundFormat(SoundFormat.RawValue(rawValue)) }
|
||||||
|
|
||||||
public var isStereo: Bool { rawValue & 1 != 0 }
|
public var isStereo: Bool { rawValue & 1 != 0 }
|
||||||
public var is16bit: Bool { rawValue >= 2 && rawValue < 4 }
|
public var is16bit: Bool { rawValue >= 2 && rawValue < 4 }
|
||||||
@@ -94,9 +94,9 @@ extension Sound {
|
|||||||
return snd.pointee.setMicCallback.unsafelyUnwrapped({ _, buffer, length in
|
return snd.pointee.setMicCallback.unsafelyUnwrapped({ _, buffer, length in
|
||||||
let samples = UnsafeMutableBufferPointer(start: buffer, count: Int(length))
|
let samples = UnsafeMutableBufferPointer(start: buffer, count: Int(length))
|
||||||
return Sound.micCallback?(samples) == true ? 1 : 0
|
return Sound.micCallback?(samples) == true ? 1 : 0
|
||||||
}, nil, CPlaydate.MicSource(source.rawValue)) != 0
|
}, nil, CPlaydate.MicSource(CPlaydate.MicSource.RawValue(source.rawValue))) != 0
|
||||||
} else {
|
} else {
|
||||||
return snd.pointee.setMicCallback.unsafelyUnwrapped(nil, nil, CPlaydate.MicSource(source.rawValue)) != 0
|
return snd.pointee.setMicCallback.unsafelyUnwrapped(nil, nil, CPlaydate.MicSource(CPlaydate.MicSource.RawValue(source.rawValue))) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ extension Sound {
|
|||||||
// The callback will not be invoked; balance the retain.
|
// The callback will not be invoked; balance the retain.
|
||||||
box.release()
|
box.release()
|
||||||
}
|
}
|
||||||
return AccessReply(rawValue: reply.rawValue) ?? .ask
|
return AccessReply(rawValue: UInt32(reply.rawValue)) ?? .ask
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current headphone and headset-microphone state.
|
/// The current headphone and headset-microphone state.
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ extension Sound {
|
|||||||
case lowShelf = 5
|
case lowShelf = 5
|
||||||
case highShelf = 6
|
case highShelf = 6
|
||||||
|
|
||||||
var cValue: TwoPoleFilterType { TwoPoleFilterType(rawValue) }
|
var cValue: TwoPoleFilterType { TwoPoleFilterType(TwoPoleFilterType.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private var retainedFrequencyModulator: SignalValue?
|
private var retainedFrequencyModulator: SignalValue?
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ extension Sound {
|
|||||||
case arpeggiator = 6
|
case arpeggiator = 6
|
||||||
case function = 7
|
case function = 7
|
||||||
|
|
||||||
var cValue: LFOType { LFOType(rawValue) }
|
var cValue: LFOType { LFOType(LFOType.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
var function: ((LFO) -> Float)?
|
var function: ((LFO) -> Float)?
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ extension Sound {
|
|||||||
case poDigital = 6
|
case poDigital = 6
|
||||||
case poVosim = 7
|
case poVosim = 7
|
||||||
|
|
||||||
var cValue: SoundWaveform { SoundWaveform(rawValue) }
|
var cValue: SoundWaveform { SoundWaveform(SoundWaveform.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Custom generator callbacks. Samples are in signed Q8.24 format.
|
/// Custom generator callbacks. Samples are in signed Q8.24 format.
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ public final class Sprite {
|
|||||||
case bounce = 3
|
case bounce = 3
|
||||||
|
|
||||||
init(_ response: SpriteCollisionResponseType) {
|
init(_ response: SpriteCollisionResponseType) {
|
||||||
self = CollisionResponse(rawValue: response.rawValue) ?? .freeze
|
self = CollisionResponse(rawValue: UInt32(response.rawValue)) ?? .freeze
|
||||||
}
|
}
|
||||||
var cValue: SpriteCollisionResponseType { SpriteCollisionResponseType(rawValue) }
|
var cValue: SpriteCollisionResponseType { SpriteCollisionResponseType(SpriteCollisionResponseType.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about a single collision, mirroring `SpriteCollisionInfo`.
|
/// Information about a single collision, mirroring `SpriteCollisionInfo`.
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ extension System {
|
|||||||
public struct Buttons: OptionSet, Sendable {
|
public struct Buttons: OptionSet, Sendable {
|
||||||
public let rawValue: UInt32
|
public let rawValue: UInt32
|
||||||
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
||||||
init(_ buttons: PDButtons) { self.rawValue = buttons.rawValue }
|
init(_ buttons: PDButtons) { self.rawValue = UInt32(buttons.rawValue) }
|
||||||
var cValue: PDButtons { PDButtons(rawValue) }
|
var cValue: PDButtons { PDButtons(PDButtons.RawValue(rawValue)) }
|
||||||
|
|
||||||
public static let left = Buttons(kButtonLeft)
|
public static let left = Buttons(kButtonLeft)
|
||||||
public static let right = Buttons(kButtonRight)
|
public static let right = Buttons(kButtonRight)
|
||||||
@@ -34,8 +34,8 @@ extension System {
|
|||||||
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
||||||
|
|
||||||
public static let none = Peripherals([])
|
public static let none = Peripherals([])
|
||||||
public static let accelerometer = Peripherals(rawValue: kAccelerometer.rawValue)
|
public static let accelerometer = Peripherals(rawValue: UInt32(kAccelerometer.rawValue))
|
||||||
public static let all = Peripherals(rawValue: kAllPeripherals.rawValue)
|
public static let all = Peripherals(rawValue: UInt32(kAllPeripherals.rawValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The system language.
|
/// The system language.
|
||||||
@@ -46,9 +46,9 @@ extension System {
|
|||||||
case system = 2
|
case system = 2
|
||||||
|
|
||||||
init(_ language: PDLanguage) {
|
init(_ language: PDLanguage) {
|
||||||
self = Language(rawValue: language.rawValue) ?? .english
|
self = Language(rawValue: UInt32(language.rawValue)) ?? .english
|
||||||
}
|
}
|
||||||
var cValue: PDLanguage { PDLanguage(rawValue) }
|
var cValue: PDLanguage { PDLanguage(PDLanguage.RawValue(rawValue)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A calendar date and time, mirroring `PDDateTime`.
|
/// A calendar date and time, mirroring `PDDateTime`.
|
||||||
@@ -97,9 +97,9 @@ extension System {
|
|||||||
public let rawValue: UInt32
|
public let rawValue: UInt32
|
||||||
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
public init(rawValue: UInt32) { self.rawValue = rawValue }
|
||||||
|
|
||||||
public static let charging = PowerStatus(rawValue: kPDPowerStatusCharging.rawValue)
|
public static let charging = PowerStatus(rawValue: UInt32(kPDPowerStatusCharging.rawValue))
|
||||||
public static let usb = PowerStatus(rawValue: kPDPowerStatusUsb.rawValue)
|
public static let usb = PowerStatus(rawValue: UInt32(kPDPowerStatusUsb.rawValue))
|
||||||
public static let screws = PowerStatus(rawValue: kPDPowerStatusScrews.rawValue)
|
public static let screws = PowerStatus(rawValue: UInt32(kPDPowerStatusScrews.rawValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OS, language, and pdx version information, mirroring `PDInfo`.
|
/// OS, language, and pdx version information, mirroring `PDInfo`.
|
||||||
@@ -239,7 +239,7 @@ extension System {
|
|||||||
nonisolated(unsafe) private static var buttonCallback: ((Buttons, Bool, UInt32) -> Int32)?
|
nonisolated(unsafe) private static var buttonCallback: ((Buttons, Bool, UInt32) -> Int32)?
|
||||||
|
|
||||||
public static func setPeripheralsEnabled(_ peripherals: Peripherals) {
|
public static func setPeripheralsEnabled(_ peripherals: Peripherals) {
|
||||||
api.pointee.setPeripheralsEnabled.unsafelyUnwrapped(PDPeripherals(peripherals.rawValue))
|
api.pointee.setPeripheralsEnabled.unsafelyUnwrapped(PDPeripherals(PDPeripherals.RawValue(peripherals.rawValue)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The most recent accelerometer reading, in g. Enable the accelerometer
|
/// The most recent accelerometer reading, in g. Enable the accelerometer
|
||||||
@@ -477,7 +477,7 @@ extension System {
|
|||||||
public static var volume: Float { api.pointee.getVolume.unsafelyUnwrapped() }
|
public static var volume: Float { api.pointee.getVolume.unsafelyUnwrapped() }
|
||||||
|
|
||||||
public static var powerStatus: PowerStatus {
|
public static var powerStatus: PowerStatus {
|
||||||
PowerStatus(rawValue: api.pointee.getPowerStatus.unsafelyUnwrapped().rawValue)
|
PowerStatus(rawValue: UInt32(api.pointee.getPowerStatus.unsafelyUnwrapped().rawValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Quits the game and returns to the launcher.
|
/// Quits the game and returns to the launcher.
|
||||||
|
|||||||
Reference in New Issue
Block a user