Standardized some arguments labels throughout the Playdate bindings target.
This commit is contained in:
@@ -253,7 +253,7 @@ try save.write(JSON.encode(.table([
|
|||||||
])))
|
])))
|
||||||
try save.close()
|
try save.close()
|
||||||
|
|
||||||
let loaded = try JSON.decodeFile(at: "save.json")
|
let loaded = try JSON.decodeFile(path: "save.json")
|
||||||
if case .table(let entries) = loaded, case .int(let level)? = entries["level"] {
|
if case .table(let entries) = loaded, case .int(let level)? = entries["level"] {
|
||||||
Game.shared.level = level
|
Game.shared.level = level
|
||||||
}
|
}
|
||||||
@@ -301,6 +301,7 @@ try Lua.addFunction(double, name: "mylib.double")
|
|||||||
|
|
||||||
- **Namespaces.** The subsystem namespaces (`System`, `Graphics`, `Sound`, …) live at the top level of the module; only the raw C API bootstrap stays under `Playdate` (`Playdate.initialize(with:)`, `Playdate.api`). On a name collision with another module, qualify with the module name: `PlaydateKit.System`.
|
- **Namespaces.** The subsystem namespaces (`System`, `Graphics`, `Sound`, …) live at the top level of the module; only the raw C API bootstrap stays under `Playdate` (`Playdate.initialize(with:)`, `Playdate.api`). On a name collision with another module, qualify with the module name: `PlaydateKit.System`.
|
||||||
- **Properties vs. methods.** State the OS can report back is a property: read-write where the C API has a get/set pair (`Display.refreshRate`, `Source.volume`), get-only where it only has a getter (`Display.fps`). A `set…` method means the C API is write-only there (`Display.setScale`, `Synth.setAttackTime`) or setting takes extra arguments — a property getter never invents a value the OS can't return. Callbacks are installed with `set…Callback`/`set…Function` methods.
|
- **Properties vs. methods.** State the OS can report back is a property: read-write where the C API has a get/set pair (`Display.refreshRate`, `Source.volume`), get-only where it only has a getter (`Display.fps`). A `set…` method means the C API is write-only there (`Display.setScale`, `Synth.setAttackTime`) or setting takes extra arguments — a property getter never invents a value the OS can't return. Callbacks are installed with `set…Callback`/`set…Function` methods.
|
||||||
|
- **Paths.** APIs that load a single file label the argument `path:` (`Bitmap(path:)`, `JSON.decodeFile(path:)`); directory operations use `at:` (`File.listFiles(at:)`). The POSIX-named `File.stat`, `File.mkdir`, and `File.unlink` take their path unlabeled, like their C namesakes.
|
||||||
- **Errors.** Fallible operations use typed throws — `throws(PlaydateError)` generally, `throws(Network.NetError)` for network I/O — so `catch` gives you a concrete type, and no `any Error` existentials are needed.
|
- **Errors.** Fallible operations use typed throws — `throws(PlaydateError)` generally, `throws(Network.NetError)` for network I/O — so `catch` gives you a concrete type, and no `any Error` existentials are needed.
|
||||||
- **Ownership.** A wrapper that *creates* a C object frees it on `deinit`; keep the wrapper referenced for as long as you use it. Wrappers vending OS-owned objects (a `Bitmap` from a `BitmapTable`, a track from a `Sequence`, …) don't free them — keep the owner alive instead, as documented on each API. Resources a C object keeps referencing (a sprite's image, a synth's sample, modulators, menu-item option titles) are retained by the wrapper automatically.
|
- **Ownership.** A wrapper that *creates* a C object frees it on `deinit`; keep the wrapper referenced for as long as you use it. Wrappers vending OS-owned objects (a `Bitmap` from a `BitmapTable`, a track from a `Sequence`, …) don't free them — keep the owner alive instead, as documented on each API. Resources a C object keeps referencing (a sprite's image, a synth's sample, modulators, menu-item option titles) are retained by the wrapper automatically.
|
||||||
- **Callbacks.** Where the C API provides a userdata slot, closures are supported everywhere and delivered back with the right wrapper. A few C callbacks have no userdata (serial messages, headphone changes, scoreboard
|
- **Callbacks.** Where the C API provides a userdata slot, closures are supported everywhere and delivered back with the right wrapper. A few C callbacks have no userdata (serial messages, headphone changes, scoreboard
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ extension JSON {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Opens and decodes the JSON file at `path`.
|
/// Opens and decodes the JSON file at `path`.
|
||||||
public static func decodeFile(at path: String) throws(PlaydateError) -> Value {
|
public static func decodeFile(path: String) throws(PlaydateError) -> Value {
|
||||||
let file = try File.Handle(path: path, mode: [.read, .readData])
|
let file = try File.Handle(path: path, mode: [.read, .readData])
|
||||||
return try decode(file: file)
|
return try decode(file: file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ extension Sound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a sequence and loads the MIDI file at `path`.
|
/// Creates a sequence and loads the MIDI file at `path`.
|
||||||
public convenience init(midiFilePath: String) throws(PlaydateError) {
|
public convenience init(path: String) throws(PlaydateError) {
|
||||||
self.init()
|
self.init()
|
||||||
try loadMIDIFile(path: midiFilePath)
|
try loadMIDIFile(path: path)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|||||||
Reference in New Issue
Block a user