func testFpVar(t *testing.T) { const expected = 42 f := C.intFunc(C.fortytwo) res1 := C.bridge_int_func(f) if r1 := int(res1); r1 != expected { t.Errorf("got %d, want %d", r1, expected) } res2 := callCBridge(f) if r2 := int(res2); r2 != expected { t.Errorf("got %d, want %d", r2, expected) } r3 := callBridge(f) if r3 != expected { t.Errorf("got %d, want %d", r3, expected) } }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) f := C.intFunc(C.fortytwo) fmt.Println(int(C.bridge_int_func(f))) // Output: 42 }
func main() { f := C.intFunc(C.fortytwo) fmt.Println(int(C.bridge_int_func(f))) // Output: 42 }
//export Bridge // This Go function is called from C func Bridge(param string, callback unsafe.Pointer) string { uuid := uuid.NewV4() cs := C.CString("Hello World!") return fmt.Sprintf("[%s] %s = %d (%d)", uuid.String(), param, C.bridge_int_func(C.intFunc(callback)), C.CBridge(cs)) }
func callCBridge(f C.intFunc) C.int { return C.bridge_int_func(f) }
func callBridge(f C.intFunc) int { return int(C.bridge_int_func(f)) }