Skip to content

Instantly share code, notes, and snippets.

View regnarg's full-sized avatar

Filip Štědronský regnarg

View GitHub Profile
@regnarg
regnarg / screpl.p6
Created December 28, 2016 09:23
Run Perl 6 REPL in context of a script
#!/usr/bin/perl6
use nqp;
class MyREPL is REPL {
# Simplified copy-paste of one iteration of repl-loop
method eval-in-ctx($code, *%adverbs) {
my $*CTXSAVE := self;
my $*MAIN_CTX;
@regnarg
regnarg / REPLHere.pm6
Created December 28, 2016 14:15
Perl 6: Invoke a REPL in the context of the caller (debugging tool)
unit package Debug::REPLHere;
use nqp;
our sub repl-here($context=Nil) is export {
my $comp = nqp::getcomp('perl6');
my $repl = REPL.new($comp, {});
my $nqpctx := nqp::getattr(nqp::decont($context // CALLER::), PseudoStash, '$!ctx');
$repl.^attributes.first('$!save_ctx').set_value($repl, $nqpctx);
$repl.repl-loop;