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