-
-
Save zoffixznet/548274905bc9230c4151e3b7df5dc0f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replify 「 | |
say 'Hello to your custom REPL! Type `say $a` to print the secret variable'; | |
my $a = "The value is {rand}"; | |
」; | |
sub replify (Str:D \pre-code = '') { | |
use nqp; | |
my %adverbs; # command line args like --MFoo | |
my \r := REPL.new: nqp::getcomp('perl6'), %adverbs; | |
my \enc := %adverbs<encoding>:v.Str; | |
enc && enc ne 'fixed_8' && $*IN.set-encoding: enc; | |
my $*CTXSAVE := r; | |
my $*MAIN_CTX; | |
pre-code and r.repl-eval: pre-code, $, :outer_ctx(nqp::getattr(r, REPL, '$!save_ctx')), | |
|%adverbs; | |
$*MAIN_CTX and nqp::bindattr(r, REPL, '$!save_ctx', $*MAIN_CTX); | |
r.repl-loop: :interactive, |%adverbs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment