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
+6 -6
View File
@@ -30,7 +30,7 @@ extension Lua {
/// for namespacing, e.g. "mylib.myfunc").
public static func addFunction(_ function: CFunction, name: String) throws(PlaydateError) {
var error: UnsafePointer<CChar>?
let ok = name.withPlaydateCString {
let ok = name.withCString {
luaAPI.pointee.addFunction.unsafelyUnwrapped(function, $0, &error) != 0
}
if !ok { throw PlaydateError(cString: error) }
@@ -72,7 +72,7 @@ extension Lua {
retainedBuffers.append(UnsafeMutableRawPointer(constantsBuffer))
var error: UnsafePointer<CChar>?
let ok = name.withPlaydateCString {
let ok = name.withCString {
luaAPI.pointee.registerClass.unsafelyUnwrapped($0, registrationsBuffer,
values.isEmpty ? nil : constantsBuffer,
isStatic ? 1 : 0, &error) != 0
@@ -153,7 +153,7 @@ extension Lua {
var userdataObject: OpaquePointer?
// The C API takes a non-const class name but only reads it, so the
// stack copy can be passed with a mutating cast.
let object = type.withPlaydateCString { cType in
let object = type.withCString { cType in
luaAPI.pointee.getArgObject.unsafelyUnwrapped(
Int32(position), UnsafeMutablePointer(mutating: cType), &userdataObject)
}
@@ -197,7 +197,7 @@ extension Lua {
/// Pushes a string onto the stack.
public static func push(_ value: String) {
value.withPlaydateCString { luaAPI.pointee.pushString.unsafelyUnwrapped($0) }
value.withCString { luaAPI.pointee.pushString.unsafelyUnwrapped($0) }
}
/// Pushes raw bytes (which may contain embedded zeros) onto the stack
@@ -226,7 +226,7 @@ extension Lua {
valueCount: Int = 0) -> UDObject? {
// The C API takes a non-const class name but only reads it, so the
// stack copy can be passed with a mutating cast.
let pointer = type.withPlaydateCString { cType in
let pointer = type.withCString { cType in
luaAPI.pointee.pushObject.unsafelyUnwrapped(
object, UnsafeMutablePointer(mutating: cType), Int32(valueCount))
}
@@ -240,7 +240,7 @@ extension Lua {
/// first. Calling Lua from Swift has overhead; use sparingly.
public static func callFunction(_ name: String, argumentCount: Int = 0) throws(PlaydateError) {
var error: UnsafePointer<CChar>?
let ok = name.withPlaydateCString {
let ok = name.withCString {
luaAPI.pointee.callFunction.unsafelyUnwrapped($0, Int32(argumentCount), &error) != 0
}
if !ok { throw PlaydateError(cString: error) }