From f74a8d8e457341e75ba1a69343e28172511415ce Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 16 Feb 2022 16:22:52 +0100 Subject: [PATCH] allow making REPL using preloaded interpreter --- bin/rpl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/rpl b/bin/rpl index 720b6be..c3819b6 100755 --- a/bin/rpl +++ b/bin/rpl @@ -6,11 +6,14 @@ require 'readline' require 'rpl' class RplRepl - def initialize - @interpreter = Rpl.new + def initialize( interpreter ) + interpreter ||= Rpl.new + @interpreter = interpreter end def run + print_stack unless @interpreter.stack.empty? + Readline.completion_proc = proc do |s| ( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/) end