On Tue, Jul 17, 2012 at 6:27 PM, Aaron Patterson
<tenderlove / ruby-lang.org> wrote:
>
>     class RubyVM
>       class InstructionSequence
>         address =3D DL::Handle::DEFAULT['rb_iseq_load']
>         func =3D Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3, DL::=
TYPE_VOIDP)
>
>         define_singleton_method(:load) do |data, parent =3D nil, opt =3D =
nil|
>           func.call(DL.dlwrap(data), parent, opt).to_value
>         end
>       end
>     end
>

For some reason ::DEFAULT doesn't work on windows, so a bit of tweak:

    require 'rbconfig'
    require 'dl'
    require 'fiddle'
    require 'minitest/autorun'

    class RubyVM
      class InstructionSequence
        handle =3D DL::Handle.new(RbConfig::CONFIG["RUBY_SO_NAME"])
        address =3D handle['rb_iseq_load']
        func =3D Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3,
DL::TYPE_VOIDP)

        define_singleton_method(:load) do |data, parent =3D nil, opt =3D ni=
l|
          func.call(DL.dlwrap(data), parent, opt).to_value
        end
      end
    end

    class TestISeq < MiniTest::Unit::TestCase
      def test_load
        ins   =3D RubyVM::InstructionSequence.new '5 + 10'
        other =3D RubyVM::InstructionSequence.load ins.to_a
        assert_equal ins.eval, other.eval
      end
    end

That or simply: DL::Handle.new (no argument) which will resolve to libruby =
DLL.

--=20
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exup=E9ry