-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from skiptools/anybridge
Bridge 'Any' types
- Loading branch information
Showing
13 changed files
with
447 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 Skip | ||
// | ||
// This is free software: you can redistribute and/or modify it | ||
// under the terms of the GNU Lesser General Public License 3.0 | ||
// as published by the Free Software Foundation https://fsf.org | ||
|
||
#if SKIP | ||
|
||
/// An opaque reference to a Swift object. | ||
public typealias SwiftObjectPointer = Int64 | ||
public let SwiftObjectNil = Int64(0) | ||
|
||
/// Return a Swift object pointer to a Kotlin instance, else `SwiftObjectNil`. | ||
public func Swift_peer(of object: Any) -> SwiftObjectPointer { | ||
let peer = (object as? SwiftPeerBridged)?.Swift_peer() | ||
return peer ?? SwiftObjectNil | ||
} | ||
|
||
/// Protocol added to a Kotlin projection type backed by a Swift peer object. | ||
public protocol SwiftPeerBridged { | ||
func Swift_peer() -> SwiftObjectPointer | ||
} | ||
|
||
/// Marker type used to guarantee uniqueness of our `Swift_peer` constructor. | ||
public final class SwiftPeerMarker { | ||
} | ||
|
||
/// Return a closure that creates a Swift projection of this Kotlin instance, else nil. | ||
public func Swift_projection(of object: Any, options: Int) -> (() -> Any)? { | ||
return (object as? SwiftProjectable)?.Swift_projection(options: options) | ||
} | ||
|
||
/// Protocol added to a Kotlin type that can project to Swift. | ||
public protocol SwiftProjectable { | ||
func Swift_projection(options: Int) -> () -> Any | ||
} | ||
|
||
/// Return the `BridgedTypes` enum case name for the given Kotlin/Java object's type. | ||
public func bridgedTypeStringOf(_ object: Any) -> String { | ||
return bridgedTypeOf(object).name | ||
} | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.