forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrapperConverter.go
81 lines (73 loc) · 1.56 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package imgui
// #include "imguiWrapperTypes.h"
// #include <stdlib.h>
import "C"
import (
"fmt"
"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
}
func wrapStringPointer(value *string) (wrapped *C.char, finisher func()) {
if value != nil {
//fmt.Printf("wrapStringPointer: %v - %v\n", value, *value)
wrapped = C.CString(*value)
//fmt.Printf("C wrapped: %v\n", wrapped)
finisher = func() {
fmt.Printf("gonna free this shit: %v - the value is: %v\n", unsafe.Pointer(wrapped), *value)
*value = C.GoString(wrapped)
C.free(unsafe.Pointer(wrapped))
} // nolint: gas
} else {
finisher = func() {}
}
return
}