Skip to content

Commit

Permalink
- Blocks passed as callbacks to Perl modules will automatically conve…
Browse files Browse the repository at this point in the history
…rt the Perl arguments into Sidef objects.

In addition, the callback is called as a block (with method `run`), which doesn't require unpacking of the arguments.
  • Loading branch information
trizen committed Dec 10, 2015
1 parent e27af50 commit 8c7debc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Sidef/Types/Block/Block.pm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ package Sidef::Types::Block::Block {
local *UNIVERSAL::AUTOLOAD = $ref;
if (defined($a) || defined($b)) { push @args, $a, $b }
elsif (defined($_)) { unshift @args, $_ }
$self->call(@args);
$self->run(map { Sidef::Perl::Perl->to_sidef($_) } @args);
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/Games/asciiplanes.sf
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ if (!ARGV.is_empty) {
'hit-char=s' => func(_,v) { hit_char = Str(v) },
'miss-char=s' => func(_,v) { miss_char = Str(v) },
'wrap!' => func(_,v) { wrap_plane = Bool(v) },
'help|h|?' => usage,
'version|v|V' => ver,
'help|h|?' => func(*_) { usage() },
'version|v|V' => func(*_) { ver() },
);
}

Expand Down
3 changes: 1 addition & 2 deletions scripts/Tests/amb_nested_loops.sf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/ruby

var code = { |*arr|
var words = arr.map {|item| Perl.to_sidef(item) };
var code = { |*words|

var chr = words[0].last;
words.ft(1).each { |word|
Expand Down

0 comments on commit 8c7debc

Please sign in to comment.