I'm trying to incorporate a C library into my Go application. The interface to the C library uses a callback to handle logging. It ends up looking something like this:
/*
#include "clibrary/header.h"
void log_callback(const char * log)
{
/* I'd like to get this log value to use in my Go code */
fprintf(stderr, "Log is: %s
", log);
}
/* Using this wrapper method so the callback can be added to
the function call since it seems from my reading that
access to a C pointer to a function is difficult in CGO.
*/
int do_c_stuff_wrapper(Context * context)
{
return do_c_stuff(context, log_callback)
}
*/
import "C"
import "fmt"
func DoCStuff() {
c_context := C.init_context()
ret := C.do_c_stuff_wrapper(c_context)
fmt.Printf("The return value is %v
", ret)
}
I'd like to get the log value from the callback "back" to the Go code so I can work with it and I'm drawing a blank on how to do that.