passing strings to Go

17 views
Skip to first unread message

Michael Krisher

unread,
Oct 15, 2015, 10:51:55 PM10/15/15
to ruby-ffi
I've tried a few different ways now and assume I may be missing something obvious.

All I want to do is pass a Ruby string to Go:

// Go function
func receive(s string) string {
  fmt.Println("Go String:", s)
  return s
}

# ruby code
module PassStringToGo
  extend FFI::Library
  ffi_lib File.expand_path("./receive_string.so", File.dirname(__FILE__))
  attach_function :receive, [:string], :string
end

str = "Ruby String"
PassStringToGo.receive(str)


The output in the Go function is blank.

Do I have to use a pointer?

Thanks,
-- Mike

Reply all
Reply to author
Forward
0 new messages