Ruby: irb doesn't work on Windows

前端 未结 3 1334
轻奢々
轻奢々 2021-01-15 03:30

I\'ve installed Ruby 1.93 in my windows 7 PC using Ruby 1.9.3-p194 one click installer. I can use ruby command to interpret files, but when I type irb

3条回答
  •  旧时难觅i
    2021-01-15 04:10

    If you have problem to start IRB in Ruby 1.9.3 related to fiddle you can do this:

    In rubyxxx\lib\ruby\site_ruby\x.x.x\rbreadline.rb replace:

    This:

      require 'fiddle'
      class Win32API
        DLL = {}
        TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG}
        CALL_TYPE_TO_ABI = {:stdcall => 1, :cdecl => 1, nil => 1} #Taken from Fiddle::Importer
    
        def initialize(dllname, func, import, export = "0", calltype = :stdcall)
          @proto = import.join.tr("VPpNnLlIi", "0SSI").chomp('0').split('')
          handle = DLL[dllname] ||= Fiddle.dlopen(dllname)
          @func = Fiddle::Function.new(handle[func], TYPEMAP.values_at(*@proto), CALL_TYPE_TO_ABI[calltype])
        end
    
        def call(*args)
          args.each_with_index do |x, i|
            args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if @proto[i] == "S"
            args[i], = [x].pack("I").unpack("i") if @proto[i] == "I"
          end
          @func.call(*args).to_i || 0
        end
    

    With:

      require 'dl'
      class Win32API
        DLL = {}
        TYPEMAP = {"0" => DL::TYPE_VOID, "S" => DL::TYPE_VOIDP, "I" => DL::TYPE_LONG}
    
        def initialize(dllname, func, import, export = "0", calltype = :stdcall)
          @proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
          handle = DLL[dllname] ||= DL.dlopen(dllname)
          @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, calltype)
        end
    
        def call(*args)
          import = @proto.split("")
          args.each_with_index do |x, i|
            args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if import[i] == "S"
            args[i], = [x].pack("I").unpack("i") if import[i] == "I"
          end
          ret, = @func.call(args)
          return ret || 0
        end
    

提交回复
热议问题