RosettaCodeData/Task/Call-a-foreign-language-function/Ruby/call-a-foreign-language-function-4.rb

15 lines
282 B
Ruby
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
require 'ffi'
module LibC
extend FFI::Library
ffi_lib FFI::Platform::LIBC
attach_function :strdup, [:string], :pointer
attach_function :free, [:pointer], :void
end
string = "Hello, World!"
duplicate = LibC.strdup(string)
puts duplicate.get_string(0)
LibC.free(duplicate)