https://github.com/igor-makarov/swift-ffi
Demo for exporting Swift code to use with Ruby FFI
https://github.com/igor-makarov/swift-ffi
Last synced: 2 months ago
JSON representation
Demo for exporting Swift code to use with Ruby FFI
- Host: GitHub
- URL: https://github.com/igor-makarov/swift-ffi
- Owner: igor-makarov
- Created: 2020-01-28T08:25:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-28T10:07:03.000Z (over 5 years ago)
- Last Synced: 2024-08-10T14:19:20.113Z (11 months ago)
- Language: Swift
- Size: 5.86 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# swift-ffi
[](https://travis-ci.com/igor-makarov/swift-ffi)Shows how to use Swift code in a Ruby FFI.
See [swift_ffi.swift](Sources/swift-ffi/swift_ffi.swift) for the Swift code and [run.rb](run.rb) for the Ruby code.
The Swift code is exported as free functions using `@_cdecl` attribute. It's a little undocumented, but will probably be canonized at some point.
### Note:
The string function `swift_ffi_duplicate_string` returns a 'fresh' string, which means the dealloc is the responsibility of the Ruby code in this case. The Ruby code copies and frees the string before exposing it. Different C API design might have different constraints.