mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
097adcf8b6
This is a reland of a1ad87a262
31 lines
687 B
Go
31 lines
687 B
Go
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !darwin && !windows
|
|
|
|
package gl
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// #include <stdlib.h>
|
|
import "C"
|
|
|
|
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
// corresponding Go string.
|
|
func GoStr(cstr *byte) string {
|
|
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
}
|
|
|
|
// CStr takes a Go string (with or without null-termination)
|
|
// and returns the C counterpart.
|
|
//
|
|
// The returned free function must be called once you are done using the string
|
|
// in order to free the memory.
|
|
func CStr(str string) (cstr *byte, free func()) {
|
|
cs := C.CString(str)
|
|
return (*byte)(unsafe.Pointer(cs)), func() {
|
|
C.free(unsafe.Pointer(cs))
|
|
}
|
|
}
|