twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

util.go (573B)


      1 package glfw
      2 
      3 //#include <stdlib.h>
      4 //#define GLFW_INCLUDE_NONE
      5 //#include "glfw/include/GLFW/glfw3.h"
      6 import "C"
      7 
      8 import (
      9 	"reflect"
     10 	"unsafe"
     11 )
     12 
     13 func glfwbool(b C.int) bool {
     14 	if b == C.int(True) {
     15 		return true
     16 	}
     17 	return false
     18 }
     19 
     20 func bytes(origin []byte) (pointer *uint8, free func()) {
     21 	n := len(origin)
     22 
     23 	if n == 0 {
     24 		return nil, func() {}
     25 	}
     26 
     27 	data := C.malloc(C.size_t(n))
     28 
     29 	dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
     30 		Data: uintptr(data),
     31 		Len:  n,
     32 		Cap:  n,
     33 	}))
     34 
     35 	copy(dataSlice, origin)
     36 
     37 	return &dataSlice[0], func() { C.free(data) }
     38 }