B
Bruno Boettcher
Hello!
i am having trouble writing a script for xchat...
that thing has a method to add new commands or handlers, and that method
uses coderefs....
now i have created an object with several methods, and i have a table
with the commands to add to the client, and now i am trying to find the
syntax to do this....
here you can see the different tries i made so far:
foreach my $cmd (keys(%$commands))
{
#my $funcref = \&{$this->{"leve"}->($commands->{$cmd})};
#my $funcref = \&Leve:
$commands->{$cmd});
#my $funcref = eval("\&{".$this->{"leve"}."->".$commands->{$cmd}."}");
#my $funcref = eval("\&{Leve::".$commands->{$cmd}."}");
my $funcref = eval("sub { ".$this->{"leve"}."->".$commands->{$cmd}."(@_);}");
Xchat::hook_command("l".$cmd, $funcref);
Xchat:
rint("added command handler l".$cmd." calling back on $funcref");
}#foreach my $cmd (keys(%$commands))
the version with the anon sub would be the most interesting, since that
would preserve the OO design, passing the reference of the object along
the call....
but this dooesn't seem to work... the $funcref is empty in this last
case, and none of them work....
problem is that all the cases depicted in the docu are very simple
structures.... nothing composite is ever used as an example... so i am
quite clueless here....
what would be the best way to achieve this?
thanks for any help
i am having trouble writing a script for xchat...
that thing has a method to add new commands or handlers, and that method
uses coderefs....
now i have created an object with several methods, and i have a table
with the commands to add to the client, and now i am trying to find the
syntax to do this....
here you can see the different tries i made so far:
foreach my $cmd (keys(%$commands))
{
#my $funcref = \&{$this->{"leve"}->($commands->{$cmd})};
#my $funcref = \&Leve:
#my $funcref = eval("\&{".$this->{"leve"}."->".$commands->{$cmd}."}");
#my $funcref = eval("\&{Leve::".$commands->{$cmd}."}");
my $funcref = eval("sub { ".$this->{"leve"}."->".$commands->{$cmd}."(@_);}");
Xchat::hook_command("l".$cmd, $funcref);
Xchat:
}#foreach my $cmd (keys(%$commands))
the version with the anon sub would be the most interesting, since that
would preserve the OO design, passing the reference of the object along
the call....
but this dooesn't seem to work... the $funcref is empty in this last
case, and none of them work....
problem is that all the cases depicted in the docu are very simple
structures.... nothing composite is ever used as an example... so i am
quite clueless here....
what would be the best way to achieve this?
thanks for any help