Python callable object as alias/trigger callback

Posted by Icewolf on Wed 05 May 2010 10:23 PM — 1 posts, 10,578 views.

#0
Hi, I think Mushclient does not allow a callable object to be invoked (as specified by the "script" field) by aliases/triggers. However, in Python actually a function and a callable object are equivelent.

here's an example (i'm using activepython 2.6.4):

The alias:
===============

<aliases>
  <alias
   name="aTest"
   script="ctest"
   match="ctest"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>


The code:
=====================

class CTest(object):
    def __call__(self, *args):
        world.note(u"hello")

ctest = CTest()

When you enter "ctest", an error msg box shows up:
"
Unable to invoke script subroutine "ctest" when processing alias "aTest"
"


If you rewrite the callable as a function, then it's OK.

Thanks!