1

string_operation.go (golang function)

//export AddString
func AddString(str string, v interface{}) bool {
        somestrings = append(somestrings, str);
        xyz.Compile(str, v)
        fmt.Println("Added!!\n");
    }
    return true;
}

//export SearchString
func SearchString(str string) (v interface{}, ok bool) {
    v, ok = xyz.Match(str);
    if ok == true {
        fmt.Println("Found!!");
    } else {
        fmt.Println("Not found!!");
    }
    return
}

Above golang file when exported to use in C code

string_operation.h (Exported Header file)

typedef struct { const char *p; GoInt n; } GoString;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
/* Return type for SearchStringValue */
struct SearchString_return {
    GoInterface r0; /* v */
    GoUint8 r1; /* ok */
};

extern struct SearchString_return SearchStringValue(GoString p0);
extern GoUint8 AddString(GoString p0, GoInterface p1);

Now the question is how to implement the empty interface{} in C code?

Hemant
  • 11
  • 2

0 Answers0