Skip to content

Commit 464535c

Browse files
committed
example C extension
1 parent 0962d7f commit 464535c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### Example C extension
3+
4+
Revised from [Ben Snider's tutorial](https://www.bensnider.com/wrapping-c-code-within-a-single-swift-package.html)

Sources/Clibadder/Clibadder.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import libadder
2-
protocol Addable {
2+
public protocol Addable {
33
func add(_ x: Int, _ y: Int) -> Int
44
}
55

66
public struct SimpleAdd: Addable {
7-
func add(_ x: Int, _ y: Int) -> Int {
7+
public init() {}
8+
public func add(_ x: Int, _ y: Int) -> Int {
89
return libadder.add(x, y)
910
}
1011
}
1112

1213
public struct StructAdd: Addable {
13-
func add(_ x: Int, _ y: Int) -> Int {
14+
public init() {}
15+
public func add(_ x: Int, _ y: Int) -> Int {
1416
let op = add_operation(x: x, y: y, result: 0)
1517
let result = libadder.added(op)
1618
return result.result;
1719
}
1820
}
1921

2022
public struct PointerAdd: Addable {
21-
func add(_ x: Int, _ y: Int) -> Int {
23+
public init() {}
24+
public func add(_ x: Int, _ y: Int) -> Int {
2225
var op = add_operation(x: x, y: y, result: 0)
2326
libadder.adding(&op)
2427
return op.result;

0 commit comments

Comments
 (0)