Permalink
Browse files

flesh out [gets]; handle arbitrary channels & varName param.

  • Loading branch information...
1 parent dabdbaa commit ff91a971a79a82a4824f8a016b08924087969676 @coke coke committed Jun 28, 2010
Showing with 20 additions and 3 deletions.
  1. +19 −2 src/Partcl/commands/main.pm
  2. +1 −1 t/cmd_gets.t
@@ -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) {
View
@@ -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.