> I am working on a Perl/Tkx app and trying to use the Tcl > module's CreateCommand call to feed a Perl subroutine > directly to the Tcl interpreter. There is no documentation > on how to do this directly from Tkx so I've done a bit of > code diving into the module's internals.
Looking inside Tkx.pm: ..... package Tkx::i; use Tcl; my $interp; ..... sub interp { return $interp; } ... This give me an idea that you can always get tcl Interpreter by calling Tkx::i::interp(), After figuring out that, I conclude on this: use Tkx; my $mw = Tkx::widget->new("."); $mw->new_button( -text => "Hello, world", -command => sub { $mw->g_destroy; }, )->g_pack; Tkx::i::interp()->CreateCommand('scriptSetDir', \&scriptSetDir); sub scriptSetDir { print STDERR '[',(join ',', @_),']'; return; my $dname = shift; &selectFileSystem($dname); } Tkx::eval("scriptSetDir", "/Users/kevin"); Tkx::MainLoop(); .... but even a bit better is this: use Tkx; my $mw = Tkx::widget->new("."); $mw->new_button( -text => "Hello, world", -command => sub { $mw->g_destroy; }, )->g_pack; Tkx::i::interp()->CreateCommand('scriptSetDir-hehe', sub { print STDERR '[',(join ',', @_),']'; return; }); Tkx::i::interp()->call("scriptSetDir-hehe", "/Users/kevin"); Tkx::MainLoop(); > > This is what I've come up with, but it's not working well: > > #get Tkx's interpreter instance rather than creating a new > interpreter; this is undocumented but should work my > $interp = Tkx::i::interp; > > #next, pass a Perl subroutine to the Tcl interpreter > > $interp->CreateCommand("", \&scriptSetDir, "", "", ""); sub > scriptSetDir { > > my $dname = shift; > &selectFileSystem($dname); > > } > > This call produces no output: > > Tkx::eval("scriptSetDir", "/Users/kevin"); IMO the more pure-Tcl usage from perl/Tkx the better,... Best regards, Vadim.