Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Forked from manveru/iseq.rb
Created March 1, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsisnero/d5e3b8db02de5d280ea82ecba2a5e79e to your computer and use it in GitHub Desktop.
Save dsisnero/d5e3b8db02de5d280ea82ecba2a5e79e to your computer and use it in GitHub Desktop.
require 'ffi'
module RB
extend FFI::Library
ffi_lib [:ruby]
attach_function :iseq_load, :rb_iseq_load, [:pointer, :int, :pointer], :pointer
attach_function :iseq_eval, :rb_iseq_eval, [:pointer], :pointer
attach_function :eval_string, :rb_eval_string, [:string], :pointer
end
a = RB.eval_string('RubyVM::InstructionSequence.new("puts :hi").to_a')
b = 4
c = RB.eval_string('RubyVM::InstructionSequence.compile_option')
p RB.iseq_eval(RB.iseq_load(a, b, c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment