Files
playdate-kit/Sources/PlaydateKit/Lua/Structures/UDObject.swift
T
javier c5037dd716 Swift 6.4 migration and exhancements (#1)
This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it.

Reviewed-on: #1
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-09-18 13:15:08 +00:00

32 lines
1.1 KiB
Swift

internal import CPlaydate
extension Lua {
/// A handle to a Lua-owned object. Wraps `LuaUDObject`.
public struct UDObject {
let pointer: OpaquePointer
/// Prevents garbage collection until a balancing `release()`. Returns `self`.
@discardableResult
public func retain() -> UDObject {
UDObject(pointer: luaAPI.pointee.retainObject.unsafelyUnwrapped(pointer).unsafelyUnwrapped)
}
/// Balances one `retain()`.
public func release() {
luaAPI.pointee.releaseObject.unsafelyUnwrapped(pointer)
}
/// Sets user-value `slot` (1-based) to the top stack value.
public func setUserValue(slot: UInt32) {
luaAPI.pointee.setUserValue.unsafelyUnwrapped(pointer, slot)
}
/// Pushes user-value `slot` (1-based); returns its stack position, or `nil` if 0.
@discardableResult
public func getUserValue(slot: UInt32) -> Int? {
let position = luaAPI.pointee.getUserValue.unsafelyUnwrapped(pointer, slot)
return position == 0 ? nil : Int(position)
}
}
}