-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.go
58 lines (44 loc) · 1005 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
// #cgo LDFLAGS: -L. -lbridge
// #include "bridge.h"
import "C"
import (
"log"
"unsafe"
)
type Circle struct {
ptr unsafe.Pointer
}
func NewCircle(radius float64) Circle {
return Circle{
ptr: C.DEMO_CircleNew(C.double(radius)),
}
}
func (circle Circle) Destroy() {
C.DEMO_CircleDestroy(circle.ptr)
}
func (circle Circle) Area() float64 {
return float64(C.DEMO_CircleArea(circle.ptr))
}
type Cylinder struct {
ptr unsafe.Pointer
}
func NewCylinder(radius float64, height float64) Cylinder {
return Cylinder{
ptr: C.DEMO_CylinderNew(C.double(radius), C.double(height)),
}
}
func (cylinder Cylinder) Destroy() {
C.DEMO_CylinderDestroy(cylinder.ptr)
}
func (cylinder Cylinder) Volume() float64 {
return float64(C.DEMO_CylinderVolume(cylinder.ptr))
}
func main() {
circ := NewCircle(42.0)
defer circ.Destroy()
log.Printf("circ.Area() = %23.16e", circ.Area())
cyl := NewCylinder(42.0, 20)
defer cyl.Destroy()
log.Printf("cyl.Volume() = %23.16e", cyl.Volume())
}