File: hello_ractor.rb

package info (click to toggle)
ruby-ffi 1.17.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,012 kB
  • sloc: ruby: 9,643; ansic: 7,734; xml: 151; sh: 51; makefile: 14
file content (19 lines) | stat: -rw-r--r-- 429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# See the ffi wiki for how to use FFI with Ractors:
# https://github.com/ffi/ffi/wiki/Ractors

require 'ffi'

class Ractor
  # compat with Ruby-3.4 and older
  alias value take unless method_defined? :value
end

module Foo
  extend FFI::Library
  ffi_lib FFI::Library::LIBC
  attach_function("cputs", "puts", [ :string ], :int)
  freeze
end
Ractor.new do
  Foo.cputs("Hello, World via libc puts using FFI in a Ractor")
end.value