Skip to content

Commit

Permalink
Test that passing code, scalar and hash references to call works
Browse files Browse the repository at this point in the history
  • Loading branch information
gisle committed Oct 30, 2010
1 parent 758156c commit 6bfb8ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Tcl.pm
Expand Up @@ -504,8 +504,9 @@ sub call {
# stringify hash ref, create in ::perl namespace on Tcl side
# This will be HASH(0xXXXXXX) - leave it to become part of a
# Tcl array.
my $nm = "::perl::$arg";
my $nm = $arg;
$nm =~ s/\W/_/g; # remove () from stringified name
$nm = "::perl::$nm";
unless (exists $anon_refs{$nm}) {
$widget_refs{$current_widget}->{$nm}++;
$anon_refs{$nm} = $arg;
Expand Down
26 changes: 25 additions & 1 deletion t/call.t
Expand Up @@ -7,7 +7,7 @@ use Tcl;

$| = 1;

print "1..10\n";
print "1..15\n";

my $i = Tcl->new;
my (@res, $res, $a, $b);
Expand Down Expand Up @@ -41,3 +41,27 @@ print "ok 9\n";
$a = $i->call("list", 1, scalar($i->call("list", 2, 3)), 4);
print "not " unless @$a == 3 && $a->[1][0] == 2 && $a eq "1 {2 3} 4";
print "ok 10\n";

my $v = 1;
$i->call("after", 250, sub { print "ok 11\n"; $v++; });
$i->call("vwait", \$v);
print "not " unless $v == 2;
print "ok 12\n";

$i->call("eval", <<'EOT');
proc f1 {h v} {
upvar $h arr
puts "ok $arr(ok)"
set arr(foo) 14
incr $v
}
EOT

my %h = (foo => 1, bar => 2, ok => 13);
$i->call("after", 250, "f1", \%h, \$v);
$i->call("vwait", \$v);

print "ok $h{foo}\n";

print "not " unless $v == 3;
print "ok 15\n";

0 comments on commit 6bfb8ec

Please sign in to comment.