2019-09-22 17:42:51 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-12-08 18:35:13 +01:00
|
|
|
|
2022-05-27 11:26:53 +02:00
|
|
|
//go:build !darwin && !windows
|
2018-12-08 18:35:13 +01:00
|
|
|
|
|
|
|
package gl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #include <stdlib.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
|
|
// corresponding Go string.
|
2022-11-09 04:51:02 +01:00
|
|
|
func GoStr(cstr *byte) string {
|
2018-12-08 18:35:13 +01:00
|
|
|
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
|
|
}
|
|
|
|
|
2022-11-09 08:07:30 +01:00
|
|
|
// CStr takes a Go string (with or without null-termination)
|
|
|
|
// and returns the C counterpart.
|
2018-12-08 18:35:13 +01:00
|
|
|
//
|
2022-11-09 08:07:30 +01:00
|
|
|
// The returned free function must be called once you are done using the string
|
2018-12-08 18:35:13 +01:00
|
|
|
// in order to free the memory.
|
2022-11-09 08:07:30 +01:00
|
|
|
func CStr(str string) (cstr *byte, free func()) {
|
|
|
|
cs := C.CString(str)
|
|
|
|
return (*byte)(unsafe.Pointer(cs)), func() {
|
|
|
|
C.free(unsafe.Pointer(cs))
|
2018-12-08 18:35:13 +01:00
|
|
|
}
|
|
|
|
}
|