|
Jason Del Ponte |
at Jan 22, 2013 at 5:55 am
|
⇧ |
| |
If a method is exported, it should be callable from C, but keep in mind all
input and output parameters must be
C compatible types.
http://golang.org/cmd/cgo/ near the bottom goes into
how go functions can be exported.
When using the cgo you can do the following to allow a go function to be
called from C
//export myGoFuncToCallFromC
func myGoFuncToCallFromC(p unsafe.Pointer, a *C.char) *C.char {
...
}
An example of this for c calls in the same file as the
export,
http://golang.org/misc/cgo/test/callback.goThe exported method's address needs to be exposed to the C layer though, An
example of
this:
https://github.com/jasondelponte/go-v8/blob/master/v8.go#L4. The
v8_init is a c function defined in a c source file. The local helper
method in the go file is to easily dereference the address of the function
without it getting lost in the GC. Would love to know if there is a similar
way to do that though, which doesn't require the helper method.
Cheers,
Jason
On Monday, January 21, 2013 9:39:02 PM UTC-8, Robert Sandra wrote:
just curious..
--