using interface{} values in C/C++ bindings

80 views
Skip to first unread message

Carl-Philip Hänsch

unread,
Apr 8, 2024, 7:04:01 PMApr 8
to golang-nuts
Hi,

I am currently developing a JITable interpreter for a scripting language where users can define user-defined functions with the signature

func (...interface{}) interface{}

that can interoperate with the scripts. interface{} can be bool, int, string, []interface{} or another func(...interface{}) interface{} or one of many more.

Now I want to create a C/C++ library that offers additional functions with exactly this signature. My questions:
  • interface{} is represented as a value (ptruint) and a type information pointer. Is there a way to somehow pass this information to C/C++?
  • Does C/C++ (more specific: LLVM) have a calling convention that is ABI compatible to golang? (so I can use interface{} as a pair of parameters?)
  • Is there any library code in golang that helps me to read out interface{}'s type information?

Mihai Barbu

unread,
Apr 9, 2024, 12:41:18 PMApr 9
to golang-nuts
>>yes, Is there any library code in golang that helps me to read out interface{}'s type information?

For example: 
getType(0)
getType("hello string")

func getType(v interface{}){
t := reflect.TypeOf(v) 
fmt.Printf("type is %s", t)
Reply all
Reply to author
Forward
0 new messages