RE: [tcltk-perl] Change the way that %-subs are handled.
Brought to you by:
hobbs
From: Konovalov, V. <vko...@sp...> - 2004-04-21 06:03:52
|
> I finally figured out the magic that makes the commands that > require %-substitutions to work, like so: > > my $sub = sub { > my ($X, $Y) = (Tcl::Ev('X'), Tcl::Ev('Y')); > print "X: $X Y: $Y\n"; > }; > $mw->bind('<Motion>', \\'XY', $sub); > > This double-reference to the scalar seems a little weird to me. "weirdness" is clearly stated inside Tcl.pm. This is documented, hence is not a bug :) But seriously I also dislike \\'XY' > It would of course be best if we could somehow manage to get the > substitutions as part of the command. > > Now that we properly handle command callbacks with args, I would > like to recommend this alternative: > > $mw->bind('<Motion>', [$sub, Tcl::EV('X', 'Y', ...), > "foo", ...]); > > This would magic convert to the either the same special things > that requires the Tcl::Ev in the sub, or perhaps (if I can make > the magic work), have it pass the %-subs to the Tcl side of the > callback, while maintaining the "foo", ... for the perl side. > > Any objections, or better ideas? I still hope that "correct" method is doable, namely $mw->bind('<Motion>', \&hadler), sub handler { # uses %-subs freely, print Ev('x'); } I thought this is quite doable with Ev to do some preparations first (to manage which results must be stored), and then return an object that, at a time when its result is needed, retreives it properly. I remember this could lead to complications, but still I have a feeling that is is doable. BTW, probably right now it is the right moment to check how this is implemented in Ruby or Python. Vadim. |