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>
32 lines
1.1 KiB
Swift
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)
|
|
}
|
|
}
|
|
}
|