|
1 |
| -#include <stdio.h> |
2 | 1 | #include "libhello.h"
|
| 2 | +#include <stdio.h> |
3 | 3 |
|
4 | 4 | void go_string(void);
|
5 | 5 |
|
6 |
| - |
7 | 6 | int main() {
|
8 | 7 | go_string();
|
9 |
| - return 0; |
| 8 | + return(0); |
10 | 9 | }
|
11 | 10 |
|
12 | 11 | // Callback function to be called from Go
|
13 | 12 | void CallbackInC(char *go_str) {
|
14 |
| - printf("CallbackInC(): %s\n", go_str); |
15 |
| - GoFreeString(go_str); // Release the Go string |
| 13 | + printf("CallbackInC(): %s\n", go_str); |
| 14 | + GoFreeString(go_str); // Release the Go string |
16 | 15 | }
|
17 | 16 |
|
18 |
| - |
19 |
| - |
20 | 17 | void go_string(void){
|
21 |
| - |
22 |
| - { |
23 |
| - char *go_str = GoStringFromGo(); |
24 |
| - printf("GoStringFromGo(): %s\n", go_str); |
25 |
| - GoFreeString(go_str); // Release the Go string |
| 18 | + { |
| 19 | + char *go_str = GoStringFromGo(); |
| 20 | + printf("GoStringFromGo(): %s\n", go_str); |
| 21 | + GoFreeString(go_str); // Release the Go string |
| 22 | + } |
| 23 | + { |
| 24 | + GoStringToGo("Calling from C"); |
| 25 | + } |
| 26 | + { |
| 27 | + Demo_Array *go_array = GoArrayFromGo(); |
| 28 | + printf("GoArrayFromGo():"); |
| 29 | + int i; |
| 30 | + for (i = 0; i < go_array->len; i++) { |
| 31 | + printf(" %d", ((int *)(go_array->data))[i]); |
26 | 32 | }
|
27 |
| - { |
28 |
| - GoStringToGo("Calling from C"); |
29 |
| - } |
30 |
| - { |
31 |
| - Demo_Array *go_array = GoArrayFromGo(); |
32 |
| - printf("GoArrayFromGo():"); |
33 |
| - int i; |
34 |
| - for(i=0; i < go_array->len; i++) { |
35 |
| - printf(" %d", ( (int *)(go_array->data) )[i]); |
36 |
| - } |
37 |
| - printf("\n"); |
38 |
| - GoFreeArray(go_array); // Release the Demo_Array |
39 |
| - } |
40 |
| - |
41 |
| - // Pass array to a Go library function |
42 |
| - { |
43 |
| - int c_array[] = { 4, 5, 6 }; |
44 |
| - // Create a Demo_Array wrapper for the native C array |
45 |
| - Demo_Array go_array = { c_array, sizeof(c_array)/sizeof(c_array[0]) }; |
46 |
| - } |
47 |
| - { |
48 |
| - GoFunctionToGo(&CallbackInC); |
49 |
| - } |
50 |
| - |
51 |
| - // Receive a Go callback function and call it from here |
52 |
| - { |
53 |
| - void (*go_ptr)() = GoFunctionFromGo(); |
54 |
| - (go_ptr)("Calling from C"); |
55 |
| - } |
| 33 | + printf("\n"); |
| 34 | + GoFreeArray(go_array); // Release the Demo_Array |
| 35 | + } |
| 36 | + |
| 37 | + // Pass array to a Go library function |
| 38 | + { |
| 39 | + int c_array[] = { 4, 5, 6 }; |
| 40 | + // Create a Demo_Array wrapper for the native C array |
| 41 | + Demo_Array go_array = { c_array, sizeof(c_array) / sizeof(c_array[0]) }; |
| 42 | + } |
| 43 | + { |
| 44 | + GoFunctionToGo(&CallbackInC); |
| 45 | + } |
| 46 | + |
| 47 | + // Receive a Go callback function and call it from here |
| 48 | + { |
| 49 | + void (*go_ptr)() = GoFunctionFromGo(); |
| 50 | + (go_ptr)("Calling from C"); |
| 51 | + } |
56 | 52 | }
|
0 commit comments