forked from jcowgar/go-iup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
107 lines (83 loc) · 2.26 KB
/
common.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Copyright (C) 2011 by Jeremy Cowgar <[email protected]>
This file is part of go-iup.
go-iup is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
go-iup is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with go-iup. If not, see <http://www.gnu.org/licenses/>.
*/
package iup
/*
#include <stdlib.h>
#include <iup.h>
*/
import "C"
import "unsafe"
const (
// go-iup version string.
//
// go-iup version string is based off the built-against version
// code of Iup with the addition of a `go-iup' version code
// as the forth digit. i.e. 3.5.0.1 means that this version of
// go-iup was built with Iup 3.5.0 in mind and is the `.1' release
// of go-iup against Iup 3.5.0.
IupGoVersion = "3.5.0.1"
)
// Primary widget handle type.
type Ihandle C.Ihandle
func (ih *Ihandle) C() *C.Ihandle {
return (*C.Ihandle)(ih)
}
func IHandleArrayToC(ihs []*Ihandle) []*C.Ihandle {
max := len(ihs)
result := make([]*C.Ihandle, max+1)
for k, v := range ihs {
result[k] = (*C.Ihandle)(v)
}
result[max] = nil
return result
}
func StringArrayToC(strs []string) []*C.char {
max := len(strs)
result := make([]*C.char, max+1)
for k, v := range strs {
result[k] = C.CString(v)
}
result[max] = nil
return result
}
func FreeCStringArray(strs []*C.char) {
for _, v := range strs {
if v != nil {
C.free(unsafe.Pointer(v))
}
}
}
func Float64ArrayToC(nums []float64) []C.float {
result := make([]C.float, len(nums))
for k, v := range nums {
result[k] = C.float(v)
}
return result
}
func ByteArrayToCUCharArray(content []byte) []C.uchar {
cContent := make([]C.uchar, len(content))
for i, v := range content {
cContent[i] = (C.uchar)(v)
}
cContent[len(content)] = 0
return cContent
}
func IntArrayToC(nums []int) []C.int {
result := make([]C.int, len(nums))
for k, v := range nums {
result[k] = C.int(v)
}
return result
}