forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperConverter.go
61 lines (55 loc) · 1.08 KB
/
WrapperConverter.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
59
60
61
package imgui
// #include "imguiWrapperTypes.h"
// #include <stdlib.h>
import "C"
import "unsafe"
func castBool(value bool) (cast C.IggBool) {
if value {
cast = 1
}
return
}
func wrapBool(goValue *bool) (wrapped *C.IggBool, finisher func()) {
if goValue != nil {
var cValue C.IggBool
if *goValue {
cValue = 1
}
wrapped = &cValue
finisher = func() {
*goValue = cValue != 0
}
} else {
finisher = func() {}
}
return
}
func wrapInt32(goValue *int32) (wrapped *C.int, finisher func()) {
if goValue != nil {
cValue := C.int(*goValue)
wrapped = &cValue
finisher = func() {
*goValue = int32(cValue)
}
} else {
finisher = func() {}
}
return
}
func wrapFloat(goValue *float32) (wrapped *C.float, finisher func()) {
if goValue != nil {
cValue := C.float(*goValue)
wrapped = &cValue
finisher = func() {
*goValue = float32(cValue)
}
} else {
finisher = func() {}
}
return
}
func wrapString(value string) (wrapped *C.char, finisher func()) {
wrapped = C.CString(value)
finisher = func() { C.free(unsafe.Pointer(wrapped)) } // nolint: gas
return
}