Skip to content

Commit

Permalink
flesh out [gets]; handle arbitrary channels & varName param.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Jun 28, 2010
1 parent dabdbaa commit ff91a97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/Partcl/commands/main.pm
Expand Up @@ -272,11 +272,28 @@ our sub format(*@args) {
}

our sub gets(*@args) {
our %CHANNELS;

if +@args < 1 || +@args > 2 {
error('wrong # args: should be "gets channelId ?varName?"');
}
my $channelId := @args.shift;
'';

my $channelId := @args[0];
my $chanObj := %CHANNELS{$channelId};
if (! pir::defined($chanObj) ) {
error("can not find channel named \"$channelId\"");
}

my $result := pir::readline__sp($chanObj);
if pir::length__is($result) >0 && pir::substr__ssi($result, -1) eq "\n" {
$result := pir::chopn__ssi($result,1);
}
if +@args == 2 {
set(@args[1], $result);
return pir::length__is($result);
} else {
return $result;
}
}

our sub glob(*@args) {
Expand Down
2 changes: 1 addition & 1 deletion t/cmd_gets.t
Expand Up @@ -13,6 +13,6 @@ eval_is {gets a b c} \

eval_is {gets #parrot} \
{can not find channel named "#parrot"} \
{bad channel} {TODO NQPRX}
{bad channel}

# vim: filetype=tcl:

0 comments on commit ff91a97

Please sign in to comment.