1234567891011121314151617181920212223242526272829303132333435 |
- package qt
- /*
- #include <stdlib.h>
- #include <stdint.h>
- typedef void (*CgoCallback)(size_t);
- void CgoInvokeCallback(size_t id);
- */
- import "C"
- import "unsafe"
- import "kumachan/standalone/qt/cgohelper"
- func str_alloc() (func(string) *C.char, func()) {
- var alloc, dealloc = cgohelper.CreateStringAllocator()
- return func(str string) *C.char {
- return (*C.char)(alloc(str))
- }, dealloc
- }
- //export invoke_callback
- func invoke_callback(id C.size_t) {
- var f = cgohelper.GetCallback(uint(id))
- f()
- }
- func addrlen(buf ([] byte)) (*C.uint8_t, C.size_t) {
- if len(buf) == 0 {
- return nil, C.size_t(0)
- } else {
- return (*C.uint8_t)(unsafe.Pointer(&(buf[0]))), C.size_t(uint(len(buf)))
- }
- }
- var cgo_callback = C.CgoCallback(C.CgoInvokeCallback)
|