Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Include I/O subs in the setting.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent d6a55c4 commit bc0b098
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions nqp-src/NQPCORE.setting
Expand Up @@ -601,6 +601,54 @@ my class NQPCapture {
}

# From src\core\IO.pm

=begin

IO Methods and Functions

=end

=begin item open
Open file.
=end item

sub open($filename, :$r, :$w, :$a, :$bin) {
my $mode := $w ?? 'w' !! ($a ?? 'wa' !! 'r');
my $handle := nqp::open($filename, $mode);
nqp::setencoding($handle, $bin ?? 'binary' !! 'utf8');
$handle;
}

=begin item close
Close handle
=end item

sub close($handle) {
nqp::closefh($handle);
}

=begin item slurp
Returns the contents of C<$filename> as a single string.
=end item

sub slurp ($filename) {
my $handle := open($filename, :r);
my $contents := nqp::readallfh($handle);
nqp::closefh($handle);
$contents;
}


=begin item spew
Write the string value of C<$contents> to C<$filename>.
=end item

sub spew($filename, $contents) {
my $handle := open($filename, :w);
nqp::printfh($handle, $contents);
nqp::closefh($handle);
}

sub print(*@args) {
for @args {
nqp::print($_);
Expand Down

0 comments on commit bc0b098

Please sign in to comment.