Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created November 7, 2022 23:23
Show Gist options
  • Save ParadoxV5/81dd242b9b0d346c9f6847a70f4674a5 to your computer and use it in GitHub Desktop.
Save ParadoxV5/81dd242b9b0d346c9f6847a70f4674a5 to your computer and use it in GitHub Desktop.
[MRI only] Hello World in Ruby – the wrong way (Ruby Fiddle study with a brief touch on MRI C API)
# frozen_string_literal: true
require 'fiddle'
include Fiddle
GREETINGS = 'hello, world'
Handle.new.then do |lib|
Function.new(
lib['rb_eval_string'],
[TYPE_CONST_STRING],
TYPE_UINTPTR_T, # VALUE
need_gvl: true
).call("$><<'#{GREETINGS}'+?\\n")
ensure
lib.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment