miqt/qt/binding.go

25 lines
584 B
Go
Raw Normal View History

package qt
// SPDX-License-Identifier: MIT
2024-08-18 07:02:32 +00:00
import (
"C"
"runtime/cgo"
"unsafe"
2024-08-18 07:02:32 +00:00
)
type miqtCallbackFunc func(argc C.int, args *C.void)
//export miqt_exec_callback
func miqt_exec_callback(cb *C.void, argc C.int, args *C.void) {
// Our CABI for all callbacks is void(int, void*).
// Our Go ABI is CallbackFunc
// Then the Go bindings can unmarshal the arguments and C.free() them as necessary
cfunc, ok := (cgo.Handle(uintptr(unsafe.Pointer(cb))).Value()).(miqtCallbackFunc)
if !ok {
panic("miqt: callback of non-callback type (heap corruption?)")
}
cfunc(argc, args)
}