Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

callback

  • Loading branch information...
commit e1d33d00d27dd060250300c928f0485853048dab 1 parent 86b19b8
@tebeka tebeka authored
View
22 2013/import-c.slide
@@ -33,7 +33,7 @@ Note that are other options (such as [[http://www.swig.org/][swig]])
.play import-c/sqrt.go
-* Strings I
+* Strings
.play import-c/str.go
@@ -41,7 +41,7 @@ Note that are other options (such as [[http://www.swig.org/][swig]])
.image import-c/picard1.jpg 400 600
-* Strings II
+* Strings
.play import-c/str2.go
@@ -49,7 +49,7 @@ Note that are other options (such as [[http://www.swig.org/][swig]])
.image import-c/picard2.jpg 400 600
-* Strings III
+* Strings
.play import-c/str3.go
@@ -57,6 +57,22 @@ Note that are other options (such as [[http://www.swig.org/][swig]])
.play import-c/struct.go
+* Calling Go from C
+
+`callback.c`
+
+.code import-c/callback/callback.c
+
+`callback.h`
+
+.code import-c/callback/callback.h
+
+* Calling Go from C
+
+`callback.go`
+
+.code import-c/callback/callback.go
+
* Case Study - snowball
- [[https://bitbucket.org/tebeka/snowball]]
View
BIN  2013/import-c/callback/callback
Binary file not shown
View
8 2013/import-c/callback/callback.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include "_cgo_export.h"
+
+void
+c_func() {
+ printf("Calling Go\n");
+ go_func();
+}
View
16 2013/import-c/callback/callback.go
@@ -0,0 +1,16 @@
+package main
+
+import "fmt"
+
+// #include "callback.h"
+import "C"
+
+//export go_func
+func go_func() {
+ fmt.Println("Hello from Go")
+}
+
+func main() {
+ C.c_func();
+}
+
View
6 2013/import-c/callback/callback.h
@@ -0,0 +1,6 @@
+#ifndef CALLBACK_H
+#define CALLBACK_H
+
+void c_func();
+
+#endif

0 comments on commit e1d33d0

Please sign in to comment.
Something went wrong with that request. Please try again.