Go integer to Ruby Numeric // // C.long(): Go int -> C long (cgo) // rb_int2inum(): C long -> Ruby Numeric (C function) // From Go, it can use C Macro (needs wrapper) func INT2NUM(n int) C.VALUE { return C.rb_int2inum(C.long(n)) }
Write wrapper in C as Go comments package main func RbString(str string) C.VALUE { cstr := C.CString(str) defer C.free(cstr) return C.rb_utf8_str_new(cstr, C.long(len(str))) } Allocation and Copy!