Skip to content

Commit

Permalink
Fix eval_path and history support in PlainBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed May 25, 2021
1 parent 0da5bc0 commit fb20cc3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/iruby/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module IRuby

module History
def eval(code, store_history)
b = TOPLEVEL_BINDING
b = eval_binding

b.local_variable_set(:_ih, In) unless b.local_variable_defined?(:_ih)
b.local_variable_set(:_oh, Out) unless b.local_variable_defined?(:_oh)
Expand Down Expand Up @@ -39,10 +39,17 @@ def initialize
require 'irb'
require 'irb/completion'
IRB.setup(nil)
@irb = IRB::Irb.new
@main = TOPLEVEL_BINDING.eval("self").dup
@workspace = IRB::WorkSpace.new(@main)
@irb = IRB::Irb.new(@workspace)
@eval_path = @irb.context.irb_path
IRB.conf[:MAIN_CONTEXT] = @irb.context
end

def eval_binding
@workspace.binding
end

def eval(code, store_history)
@irb.context.evaluate(code, 0)
@irb.context.last_value
Expand All @@ -67,6 +74,10 @@ def initialize
reset
end

def eval_binding
TOPLEVEL_BINDING
end

def eval(code, store_history)
Pry.current_line = 1
@pry.last_result = nil
Expand Down Expand Up @@ -99,7 +110,7 @@ def complete(code)
end

def reset
@pry = Pry.new(output: $stdout, target: TOPLEVEL_BINDING)
@pry = Pry.new(output: $stdout, target: eval_binding)
end
end
end

0 comments on commit fb20cc3

Please sign in to comment.