On Oct 28, 2010, at 21:54 , Jeff Hobbs wrote:

> On 28/10/2010 12:51 PM, Gisle Aas wrote:
>> For this specific problem I think we should just make passing of a hash 
>> reference to a Tcl command work the same way it works to pass a scalar 
>> reference.  It should then be possible to just use:
> 
> FWIW I thought that might be a good idea as well, but it would be done at the 
> Tcl.pm level in the 'call' subroutine.  Just adding a "$ref eq 'HASH'" check 
> that mirrors (or adds on to) the $ref eq 'SCALAR' check.

Right.  The attached patch does exactly that.  It allows this program to work 
as expected:

----------------
use strict;
use warnings;
use Tkx;

Tkx::package_require("Tktable");

my $mw = Tkx::widget->new(".");
my %hash = ( # data to display
  '0,0' => 'Goodby',
  '1,1' => 'cruel',
  '2,2' => 'world',
);

my $t = $mw->new_table(
    -rows => 5,
    -cols => 3,
    -cache => 1,
    -variable => \%hash,
);
$t->g_pack(-fill => 'both', -expand => 1);
Tkx::MainLoop();
use Data::Dump; dd \%hash;
----------------

One uglyness is that the hash is copied the first time it's passed to a Tcl 
function in this way.  I wonder if it would be possible to set up some 
arrangement with tracing on the Tcl side that calls back into Perl so that we 
can actually keep that hash on the Perl side; thus avoiding the copy.  Too 
complicated?

--Gisle



Attachment: 0001-Automatically-tie-hash-references-passed-to-Tcl.patch
Description: Binary data

Reply via email to